我正在尝试使用Python中的Tesseract检测一些数字。下面是我的起始图像以及我可以得到的结果。这是我用来达到这个目的的代码。
import pytesseract
import cv2
import numpy as np
pytesseract.pytesseract.tesseract_cmd = "C:\\Users\\choll\\AppData\\Local\\Programs\\Tesseract-OCR\\tesseract.exe"
image = cv2.imread(r'64normalwart.png')
lower = np.array([254, 254, 254])
upper = np.array([255, 255, 255])
image = cv2.inRange(image, lower, upper)
image = cv2.bitwise_not(image)
#Uses a language that should work with minecraft text, I have tried with and without, no luck
text = pytesseract.image_to_string(image, lang='mc')
print(text)
cv2.imwrite("Wartthreshnew.jpg", image)
cv2.imshow("Image", image)
cv2.waitKey(0)
我最终得到了黑底白字的数字,这看起来很不错,但是Tesseract仍然无法识别这些数字。我还注意到数字非常锯齿状,但我不知道该如何解决。有人有推荐吗?我应该如何让Tesseract能够识别这些数字?
cv2.blur()
来平滑数字的粗糙边缘。这会使图像整体变得模糊,但是tesseract可能更容易识别数字。 - sj95126