Tesseract image_to_string为空 [英] Tesseract image_to_string is empty

查看:189
本文介绍了Tesseract image_to_string为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在图像image_ball.png中有一个简单的文本.通常,Tesseract的OCR效果很好,但是对于此特定图像,它始终返回一个空字符串.

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?

版本为:

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

编辑

我也尝试过将图像转换为黑白.但是它仍然未被认可.

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''

编辑2

对于Tesseract来说,单个字符似乎也是一个问题.扩大或侵蚀图像似乎无济于事:image_1.png

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

推荐答案

扩展图像可为您提供所需的输出.

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')

这篇关于Tesseract image_to_string为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆