我正在尝试从OCR处理过的图像文本输出中重新创建段落和缩进,如下所示:
输入(想象一下这是一张图像,而不是打字):
输出(存在一些错误):
正如您所见,没有保留任何段落换行或缩进。
使用Python,我尝试了以下方法,但它不起作用(失败率过高):
代码:
def smart_format(text):
textList = text.split('\n')
temp = ''
averageLL = sum([len(line) for line in textList]) / len(textList)
for line in textList:
if (line.strip().endswith('!') or line.strip().endswith('.') or line.strip().endswith('?')) and not line.strip().endswith('-'):
if averageLL - len(line) > 7:
temp += '{{ paragraph }}' + line + '\n'
else:
temp += line + '\n'
else:
temp += line + '\n'
return temp.replace(' -\n', '').replace('-\n', '').replace(' \n', '').replace('\n', ' ').replace('{{ paragraph }}', '\n\n ')
有人有关于如何重新创建这种布局的建议吗?我正在处理旧书,所以希望能够使用LaTeX重新排版它们,因为可以轻松创建Python脚本来完成这项工作。
谢谢!
tesseract
。它是唯一免费且能够产生良好结果(对于英文文本几乎完美)的 OCR 引擎。似乎有一些文档分析在进行,但我不知道它是否能够满足我的需求... - Blender