我在和Tesseract OCR做斗争。 我有一张验血图像,上面有一张有压痕的桌子。虽然tesseract很好地识别了字符,但其结构在最终输出中没有保留。例如,查看“Emocromo con formula”(英语翻译:带公式的血液计数)下面的行。我想保留这个压痕。在
我阅读了其他相关讨论,找到了选项preserve_interword_spaces=1
。结果稍微好了一点,但正如你所见,它并不完美。在
有什么建议吗?在
更新:
我尝试了TesseractV5.0,结果是一样的。在
代码:
Tesseract版本为4.0.0.20190314
from PIL import Image
import pytesseract
# Preserve interword spaces is set to 1, oem = 1 is LSTM,
# PSM = 1 is Automatic page segmentation with OSD - Orientation and script detection
custom_config = r'-c preserve_interword_spaces=1 --oem 1 --psm 1 -l eng+ita'
# default_config = r'-c -l eng+ita'
extracted_text = pytesseract.image_to_string(Image.open('referto-1.jpg'), config=custom_config)
print(extracted_text)
# saving to a txt file
with open("referto.txt", "w") as text_file:
text_file.write(extracted_text)
比较结果:
GITHUB:
{如果你想自己创建一个存储库。在
谢谢你的帮助和你的时间
image_to_data()
函数提供了更多信息。对于每个单词,它将返回它的边界矩形。你可以用这个。在Tesseract
自动将图像分割成块。然后,您可以按块的垂直位置对其进行排序,并为每个块找到平均字符宽度(这取决于块识别的字体)。对于块中的每个单词,检查它是否接近上一个单词,如果没有相应地添加空格。我使用pandas
来简化计算,但它的用法不是必需的。别忘了结果应该用等宽字体显示。在此代码将生成以下输出:
^{pr2}$相关问题 更多 >
编程相关推荐