【问题标题】:Why does Tesseract not recognize the text on the licence plate while easyocr does?为什么 Tesseract 不能识别车牌上的文字,而 easyocr 可以?
【发布时间】:2021-04-03 20:54:58
【问题描述】:

我正在研究自动车牌识别。我可以从初始图像中裁剪Plate。但是,Tesseract 不能识别这个盘子上的文字,而 easyocr 可以。是什么原因?提前感谢您的答案。我使用代码从汽车中提取车牌并识别。

import cv2 as cv
import pytesseract
import imutils
import numpy as np
import easyocr
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'

img3 = cv.imread("4.png")
cv.imshow("Car", img3)
img3 = cv.cvtColor(img3, cv.COLOR_BGR2RGB)
gray = cv.cvtColor(img3, cv.COLOR_RGB2GRAY)

bfilter_img3 = cv.bilateralFilter(img3, 11, 17, 17)
edged_img3 = cv.Canny(bfilter_img3, 30, 200)

keypoints = cv.findContours(edged_img3.copy(), cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
contours = imutils.grab_contours(keypoints)
contours = sorted(contours, key=cv.contourArea, reverse=True)[:10]

location = None
for contour in contours:
    approx = cv.approxPolyDP(contour, 10, True)
    if len(approx) == 4:
        location = approx
        break

mask = np.zeros(gray.shape, np.uint8)
new_img = cv.drawContours(mask, [location], 0, 255, -1)
new_img = cv.bitwise_and(img3, img3, mask=mask)

print(location)
cv.imshow("Plate", new_img)


(x,y)=np.where(mask==255)
(x1,y1)=(np.min(x),np.min(y))
(x2,y2)=(np.max(x),np.max(y))
cropped_img=gray[x1:x2+1, y1:y2+1]
ret, cropped_img=cv.threshold(cropped_img,127,255,cv.THRESH_BINARY)
cv.imshow("Plate3", cropped_img)
cropped_img = cv.resize(cropped_img, None, fx=2/3, fy=2/3, interpolation=cv.INTER_AREA)
#"cropped_img= the plate image in the question"***********
text = pytesseract.image_to_string(cropped_img)
print("Text by tesseract: ",text)

""""
reader=easyocr.Reader(['en'])
text2=reader.readtext(cropped_img)
print(text2)
"""
k = cv.waitKey(0)

【问题讨论】:

  • 请添加您正在尝试的代码。
  • 这些模块都不是完美的。您没有向我们展示任何代码,因此我们无法判断您是否正确使用了 Tesseract,但easyocr 可能会更好地处理这种情况。
  • 对不起,我补充了。
  • 我用了 4 个盘子,tesseract 只认出了 1 个。问题图像中的盘子对我来说非常清楚。
  • 他们有不同的算法来检测文本,尝试将文本粘贴到空白纸上并尝试 teeseract,它可能会工作。

标签: python opencv python-tesseract


【解决方案1】:

我有点好奇你为什么使用bilateralFilterCannyfindContours 等?你看到每种方法的结果了吗?

无论如何,如果您将page-segmentation-mode 设置为6,即:

假设一个统一的文本块。

结果将是:

34 DUA34

代码:

import cv2
import pytesseract

# Load the image
img = cv2.imread("vHQ5q.jpg")

# Convert to the gray-scale
gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# OCR
print(pytesseract.image_to_string(gry, config="--psm 6"))

# Display
cv2.imshow("", gry)
cv2.waitKey(0)

你应该知道Page segmentation method

我使用 pytesseract-version-0.3.7 得到了结果。

【讨论】:

  • 我用这些函数来提取盘子。我只给了你要问的问题中的盘子。谢谢你的回复,我试试看。
  • 成功了。我更改了分段类型。
  • 您使用了哪种细分类型,您的 tesseract 版本是什么?
  • Tesseract 版本为 0.1.3。我和你一样用过6.分割模式。
猜你喜欢
  • 2013-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-16
  • 1970-01-01
  • 2020-07-24
  • 1970-01-01
  • 2016-07-24
相关资源
最近更新 更多