python - PyTesseract 在表中没有看到一些个位数

标签 python python-imaging-library ocr tesseract python-tesseract

我有一张 table 的图片

image_of_table

我正在尝试使用 PyTesseract 解析它。我已经非常接近使用这段代码了:

from PIL import Image, ImageOps
import pytesseract

og_image = Image.open('og_image.png')
grayscale = ImageOps.grayscale(og_image)
inverted = ImageOps.invert(grayscale.convert('RGB'))
print(pytesseract.image_to_string(inverted))

这似乎非常准确,只是倒数第二列中的个位数是空白的。我需要做一些不同的事情来获取这些数字吗?

最佳答案

Tesseract 有多种页面分割模式,选择正确的一种模式对于获得最佳结果是必要的。请参阅 documentation

同样在这种情况下,您可以将 tesseract 限制为特定字符集。

另一件事,tesseract 对字体和图像大小很敏感。简单的调整大小可以极大地改变结果。在这里,我将图像大小水平更改为 2 倍,垂直更改图像大小以获得最佳结果;)

结合以上所有内容,您将得到:

custom_config = r'--psm 6  -c tessedit_char_whitelist=0123456789.'
print(pytesseract.image_to_string(inverted.resize((1506, 412), Image.ANTIALIAS), config=custom_config))
      
1525 .199 303 82 161 162 7 .241
1464 .290 424 70 139 198 25 .352
1456 .292 425 116 224 224 0 .345
1433 .240 346 81 130 187 15 .275
1390 .273 373 108 217 216 3 .345
1386 .276 383 54 181 154 18 .315
1225 .208 255 68 148 129 1 .242
1218 .238 230 46 128 127 18 .273
1117 .240 268 43 113 1193 1 .308

关于python - PyTesseract 在表中没有看到一些个位数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63572276/

相关文章:

python pandas方法 "ffill"

Python PIL裁剪问题: color of cropped image screwed

python - Pillow - 更改每个像素的 RGB 值

google-apps-script - 使用 Google App Script 来自 google drive 的 OCR 图像

python - Pyinstaller 和 Tesseract OCR

Python对象绑定(bind)方法

python - 如何在 PyQt4 中以其父级为中心显示 QMessageBox?

python - 如何在SQLAlchemy中设置InnoDB存储格式?

Python - 加载大量图像而不使用所有可用的内存

java - java 的任何 OCR 技术