【问题标题】:Pytesseract converting to wrong stringsPytesseract 转换为错误的字符串
【发布时间】:2021-06-25 19:27:35
【问题描述】:

我目前正在使用 pytesseract 和 cv2 尝试读取此 Health Bar。

唯一的问题是,当我尝试使用pytesseract.image_to_string(img)将其转换为字符串时,它会将数字1之前的这一行识别为1本身,因此返回值为:11189/10180

有什么想法可以解决这个问题吗?提前非常感谢!

【问题讨论】:

  • 如果图片不变,可以裁剪。或者你可以排除第一个“1”,如果它总是存在的话。或者,您可以对图像进行预处理...

标签: python opencv cv2 python-tesseract


【解决方案1】:

如果你申请OTSU's threshold

OCR 结果是:

| 1189 / 10180

如果您不想要|/,您可以使用isalnum(),但这次的结果将是:

118910180

代码:

import cv2
import pytesseract

# Load the image
img = cv2.imread("glwMK.png")

# Convert to the gray-scale
gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# Threshold
thr = cv2.threshold(gry, 120, 255, cv2.THRESH_OTSU)[1]

# OCR
print(pytesseract.image_to_string(thr))

# Display
cv2.imshow("", thr)
cv2.waitKey(0)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-09-10
    • 2022-01-07
    • 2014-02-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-10
    • 1970-01-01
    相关资源
    最近更新 更多