【发布时间】:2021-10-26 16:22:14
【问题描述】:
我正在尝试使用 pytesseract 在 python 中读取一些字母数字字符串。 我对图像进行了预处理以减少噪音并使它们变成黑白,但我一直在读取字符串中的数字时遇到问题。
提取文本:WISOMW
使用的代码:
def convert(path):
image = cv2.imread(path)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blur = cv2.GaussianBlur(gray, (3, 3), 0)
thresh = cv2.threshold(blur, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
invert = 255 - thresh
cv2.imwrite("processed.jpg", invert)
# Perform text extraction
return pytesseract.image_to_string(invert, config="--psm 7")
我已经为 tesseract 尝试了不同的配置选项:
-
oem: 试过1、3 -
psm: 尝试了不同的模式 -
tessedit_char_whitelist:仅限字母数字字符
我觉得我错过了一些明显的东西,因为它可以可靠地读取字母字符。有什么想法吗?
【问题讨论】:
-
也许如果你尝试对图像进行腐蚀,它可能会更多地分离字符,并且 Tesseract 可能有更好的机会识别它们。
标签: python tesseract python-tesseract