如何提高EasyOCR的准确性/预测?

2024-06-13 11:21:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从车辆牌照中获取字符。 但是很少有像这样的错误预测

enter image description here

我得到的输出是UP74 BD 3465,这是错误的。有许多例子将B预测为8等等

  • 如何提高其准确性?
  • 如何预处理图像以获得正确的预测或任何其他方法?
import matplotlib.pyplot as plt
import cv2
import easyocr
from pylab import rcParams
from IPython.display import Image

rcParams['figure.figsize'] = 8, 16
reader = easyocr.Reader(['en'])

output = reader.readtext(path)
for i in range(len(output)):
    print(output[i][-2])

Tags: from图像importoutput错误字符bdreader
1条回答
网友
1楼 · 发布于 2024-06-13 11:21:34
  • 首先,我建议您阅读关于OCR图像增强的主题:LINK

  • 其次,在与上述主题相同的意义上,您可以在裁剪感兴趣区域(ROI后,使用ThresholdingGaussian FilteringHistogram Equalization来解决此特定图像的问题,因此输出图像将如下所示:

enter image description here

输出将是:

UP14 BD 3465

import cv2
import easyocr
from pylab import rcParams
# import numpy library
import numpy as np

# define the path
path = 'input.png'

# read the image
img = cv2.imread(path, 0)

# find the white rectangle
th = img.copy()
th[th<200] = 0

bbox = np.where(th>0)
y0 = bbox[0].min()
y1 = bbox[0].max()
x0 = bbox[1].min()
x1 = bbox[1].max()

# crop the region of interest (ROI)
img = img[y0:y1, x0:x1]

# histogram equalization
equ = cv2.equalizeHist(img)
# Gaussian blur
blur = cv2.GaussianBlur(equ, (5, 5), 1)

# manual thresholding
th2 = 60 # this threshold might vary!
equ[equ>=th2] = 255
equ[equ<th2]  = 0

# Now apply the OCR on the processed image
rcParams['figure.figsize'] = 8, 16
reader = easyocr.Reader(['en'])

output = reader.readtext(equ)

for i in range(len(output)):
    print(output[i][-2])

相关问题 更多 >