为什么 Tesseract 无法识别车牌上的文字,而 easyocr 可以?

Why does Tesseract not recognize the text on the licence plate while easyocr does?

我正在研究自动车牌识别。我可以从初始图像中裁剪 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)

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

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

Assume a single uniform block of text.

结果将是:

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 得到了结果。