为什么Tesseract无法检测该图像中的单个数字?

2024-09-27 07:21:47 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这张图片,我正试着用Tesseract阅读它:

enter image description here

我的代码是这样的:

pytesseract.image_to_string(im)

但是,我得到的只是LOW: 56。因此,Tesseract无法读取第一行中的1。我还尝试指定一个仅包含数字的白名单,如

pytesseract.image_to_string(im, config="tessedit_char_whitelist=0123456789.")

对图像进行腐蚀处理,但没有任何效果。有什么建议吗


Tags: to代码图像imageconfigstring图片数字
1条回答
网友
1楼 · 发布于 2024-09-27 07:21:47

Improving the quality of the output是您与Tesseract合作时的“圣经”。特别是page segmentation method应该始终显式设置。在这里(大多数情况下),我会选择 psm 6

Assume a single uniform block of text.

即使没有对图像进行进一步预处理,您也已经获得了所需的结果:

import cv2
import pytesseract

image = cv2.imread('gBrcd.png')
text = pytesseract.image_to_string(image, config=' psm 6')
print(text.replace('\f', ''))
# 1
# LOW: 56
                    
System information
                    
Platform:      Windows-10-10.0.19041-SP0
Python:        3.9.1
PyCharm:       2021.1.1
OpenCV:        4.5.2
pytesseract:   5.0.0-alpha.20201127
                    

相关问题 更多 >

    热门问题