【发布时间】: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