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

时间:2021-07-05 20:15:58

标签: python opencv image-processing ocr text-extraction

我正在尝试从车牌中获取字符。 但是很少有错误的预测,比如

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])

1 个答案:

答案 0 :(得分:2)

  • 首先,我建议您阅读有关 OCR 图像增强的主题:LINK

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

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])