【发布时间】:2020-05-25 19:03:29
【问题描述】:
我有两张几乎一模一样的图片:
其他.png
title.png
我使用 Python 脚本通过 Tesseract 提取文本:
import pytesseract
import cv2
pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe'
def process(path):
image = cv2.imread(path)
image = cv2.bitwise_not(image)
# cv2.imshow('image', image)
# cv2.waitKey(0)
results = pytesseract.image_to_string(image, lang='eng', config='')
print(path, results)
process('title.png')
process('other.png')
这是输出:
title.png ‘CP TOOL
other.png cP TOOL
我没有得到相同的结果。为什么?如何改进文本识别?
图像非常小,但我无法控制生成图像的系统。在处理图像之前,我尝试增加图像的大小:
factor = 4
width = int(image.shape[1] * factor)
height = int(image.shape[0] * factor)
dim = (width, height)
image = cv2.resize(image, dim, interpolation=cv2.INTER_AREA)
这两个图像中的文本已正确提取,但我还有其他图像(此处未包含)仍然遇到类似问题(CP 被识别为 cP 特别是)。
我试图在没有有趣效果的情况下腐蚀/扩大图像,但我对 OCR 很陌生,所以我可能做的不正确......
谢谢!
【问题讨论】: