我开始学习 OpenCV 和 Tesseract,并且在一个看似非常简单的示例上遇到了麻烦。
这是我尝试 OCR 的图像,内容为“171 m”:
我做了一些预处理。由于蓝色是文本的主色,因此我提取蓝色通道并应用简单的阈值处理。
img = cv2.imread('171_m.png')[y, x, 0]
_, thresh = cv2.threshold(img, 150, 255, cv2.THRESH_BINARY_INV)
结果图像如下所示:
然后将其放入 Tesseract 中,psm 7
对于单行:
text = pytesseract.image_to_string(thresh, config='--psm 7')
print(text)
>>> lim
我还尝试限制可能的字符,结果好一点,但还不够。
text = pytesseract.image_to_string(thresh, config='--psm 7 -c tessedit_char_whitelist=1234567890m')
print(text)
>>> 17m
OpenCV v4.1.1.
Tesseract v5.0.0-alpha.20190708
任何帮助表示赞赏。