我有一张 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/