image-processing - 正方体 image_to_string 为空
问题描述
我在图像中有一个简单的文本image_ball.png
。通常 Tesseract 的 OCR 效果很好,但是对于这个特定的图像,它总是返回一个空字符串。
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''
到目前为止,我找不到解决方法。我怎么能弄清楚这张图片出了什么问题?
版本是:
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
编辑
我还尝试将图像转换为黑白。但它仍然没有被识别。
In [6]: image = img.convert('L')
In [7]: image_to_string(image)
Out[8]: u''
编辑 2
解决方案
膨胀图像为您提供所需的输出。
image = cv2.imread("Ball.png", cv2.IMREAD_GRAYSCALE)
cv2.dilate(image, (5, 5), image)
print(pytesseract.image_to_string(image), config='--psm 7')
球
推荐阅读
- pyspark - 如何在 Pyspark 2.1 中使用窗口函数来计算星期几的出现次数
- java - Apache Fop 手动启动:“java -jar”忽略绝对路径
- mongodb - Mongo 删除大量记录中的记录
- hta - 如何从 HTML 文件输入中删除默认选项?
- php - HTML标签在代码中从他的容器中放置
- php - curl 不返回任何数据 (NULL) PHP
- python - 在做熊猫融化后绘制熊猫数据框很慢并且会产生奇怪的y轴
- css - 显示列表短代码上的响应式 CSS
- mysql - 使用 wampserver 在 Windows 10 上安装 Duplicator 备份时出错
- angular - angularfire2 - 当我离开时如何保留数据