python - 字符串识别前阈值不正确

标签 python opencv tesseract python-tesseract threshold

我正在尝试使用 pytesseract 识别一些文本,但在此之前我必须将我拥有的图片转换为二进制图片。 请注意,我首先调整了图片的大小,以便 pytesseract 更易于阅读。

查看下面的原始图片、调整后的图片、我的代码和我得到的结果,这样您就可以理解我的问题了..

Original picture

image = cv2.imread('original.png',0)
image = cv2.resize(image,None,fx=2,fy=2,interpolation=cv2.INTER_CUBIC)
cv2.imwrite("resized.png", image)

thresh = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
result = 255 - thresh
cv2.imwrite("after_threshold.png", result)

Resized picture

Picture after threshold

谢谢你的帮助:)

最佳答案

如果你删除调整大小,它似乎工作

enter image description here enter image description here

Pytesseract 的输出

32 Force

120 Initiative
Prospection

25 agilité

53 Vitalité

5 Dommages

1 Résistance Neutre
1 Portée

7% Résistance Feu
import cv2
import pytesseract

pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe"

image = cv2.imread('1.png', 0)
thresh = cv2.threshold(image, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
result = 255 - thresh 

data = pytesseract.image_to_string(result, lang='eng',config='--psm 6')
print(data)

cv2.imshow('thresh', thresh)
cv2.imshow('result', result)
cv2.waitKey()

关于python - 字符串识别前阈值不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58102801/

相关文章:

python - 当数据集的维度为 [64 x 25088] 时,我应该为 `nn.Linear(1024, 256)` 设置什么值?

OpenCV Ubuntu 安装问题

python - 有没有办法提高 opencv 视频处理的速度?

performance - 如何提高 Tesseract/Tessnet2 识别速度和准确率?

ocr - Tesseract Ocr引擎多维数据集模式-培训Tesseract

python - 如何使用 python 和 opencv 从彼此中减去两个图像?

python - 如何在 pyx 文件中使用 python 调用函数

python - 为什么在使用浏览器或请求访问页面时来自 nomatim 的响应不同?

linux - 使用 VideoCapture 来自网络摄像头的 50% 错误图片

ocr - 通过Tesseract OCR在七段显示器上进行文本检测