Tesseract image_to_string is empty

我们两清 提交于 2020-05-13 07:35:16

问题


I have a simple text in an image image_ball.png. Usually OCR of Tesseract works well, but for this certain image it returns always an empty string.

In [1]: from PIL import Image

In [2]: from pytesseract import image_to_string

In [3]: img = Image.open("image_ball.png")

In [4]: image_to_string(img)
Out[5]: u''

I could not find a workaround up-to-now. How could I figure out what is going wrong with this image?

The versions are:

In [6]: import PIL

In [7]: PIL.__version__
Out[7]: '4.0.0'


$ tesseract -v
tesseract 4.0.0
 leptonica-1.77.0
  libgif 5.1.4 : libjpeg 9c : libpng 1.6.36 : libtiff 4.0.10 : zlib 1.2.11 : libwebp 1.0.2 : libopenjp2 2.3.0
 Found AVX2
 Found AVX
 Found SSE

EDIT

I tried also to convert the image to black/white. But it is still not recognized.

In [6]: image = img.convert('L') 

In [7]: image_to_string(image)
Out[8]: u''

EDIT 2

Single characters seem also to be a problem to Tesseract. Dilating or eroding the image seems not to help: image_1.png


回答1:


Dilating image gives you the desired output.

image = cv2.imread("Ball.png", cv2.IMREAD_GRAYSCALE) 
cv2.dilate(image, (5, 5), image)
print(pytesseract.image_to_string(image), config='--psm 7')

Ball



来源:https://stackoverflow.com/questions/54561913/tesseract-image-to-string-is-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!