我正在寻找一个在python中实现的工具或想法,它将hOCR文件(由应用程序在tesseract中生成)转换为html表。其思想是利用hOCR文件中的文本位置信息(在bbox属性中提供)来创建基于所提供位置的表。我举一个例子来解释上述观点:
我使用这个来自SlideShare.net的SlideShare.net作为输入,我的应用程序使用了tesseract,我得到了下面的hOCR/xml文件作为输出。
hOCR文件:
<div class='ocr_page' id='page_2' title='image "sample_slide.jpg"; bbox 0 0 638 479; ppageno 1'>
<div class='ocr_carea' id='block_1_1' title="bbox 0 0 638 479">
<p class='ocr_par' dir='ltr' id='par_1' title="bbox 31 104 620 439">
<span class='ocr_line' id='line_1' title="bbox 32 104 613 138"><span class='ocrx_word' id='word_1' title="bbox 32 105 119 131">done:</span> <span class='ocrx_word' id='word_2' title="bbox 132 104 262 138">working</span> <span class='ocrx_word' id='word_3' title="bbox 273 105 405 138">product,</span> <span class='ocrx_word' id='word_4' title="bbox 419 104 517 132">hotels</span> <span class='ocrx_word' id='word_5' title="bbox 528 104 613 132">listed</span>
</span>
<span class='ocr_line' id='line_2' title="bbox 31 160 471 194"><span class='ocrx_word' id='word_6' title="bbox 31 164 62 187">to</span> <span class='ocrx_word' id='word_7' title="bbox 75 161 122 187">do:</span> <span class='ocrx_word' id='word_8' title="bbox 134 164 227 187">smart</span> <span class='ocrx_word' id='word_9' title="bbox 236 160 330 187">traffic</span> <span class='ocrx_word' id='word_10' title="bbox 342 160 471 194">building</span>
</span>
<span class='ocr_line' id='line_3' title="bbox 32 243 284 280"><span class='ocrx_word' id='word_11' title="bbox 32 243 128 280">seed</span> <span class='ocrx_word' id='word_12' title="bbox 148 243 284 280">round:</span>
</span>
<span class='ocr_line' id='line_4' title="bbox 71 316 619 361"><span class='ocrx_word' id='word_13' title="bbox 71 321 156 356">CEO</span> <span class='ocrx_word' id='word_14' title="bbox 171 319 240 355">will</span> <span class='ocrx_word' id='word_15' title="bbox 260 321 384 356">invest</span> <span class='ocrx_word' id='word_16' title="bbox 517 316 619 361">$30k</span>
</span>
<span class='ocr_line' id='line_5' title="bbox 75 392 620 439"><span class='ocrx_word' id='word_17' title="bbox 75 397 252 433">investor</span> <span class='ocrx_word' id='word_18' title="bbox 489 392 620 439">$120k</span>
</span>
</p>
</div>
</div>我需要的是根据下一个位置将hOCR文件转换为html表。预期的表应该类似于这张桌子。
表格单元格的大小和位置反映了hOCR文件中提供的信息。
图片来源: slideshare.net
发布于 2015-06-24 15:48:03
检查本文件。我相信它描述了你所需要的东西。在导言中:
本文档以类似XML的格式描述OCR输出的各个方面的表示。也就是说,我们定义为包含文本和其他标记的一组标记,以及这些标记的属性。但是,由于我们所代表的内容是格式化的文本,所以我们实际上并不使用新的XML作为表示形式;而是将表示嵌入到XHTML (或HTML)中,因为XHTML和XHTML处理已经定义了OCR输出表示的许多方面,否则需要额外的、单独的和特殊的定义。
XML也可以是使用XSLT转换为HTML。事实上,有一个计划这样做的项目。
此外,这个项目(hocr-工具)可能会有所帮助。
最后,请注意,乐施乐常见问题解答提到了以下内容:
使用configfile ' hocr‘tesseract将产生符合hocr规范的xhtml输出。
发布于 2017-03-06 18:18:14
以下是如何使用一些现有工具将hocr文件转换为表的方法(对于最初的问题来说也可能为时已晚):
hocr-pdf的pdf (参见https://github.com/tmbdev/hocr-tools#hocr-pdf )。只需要第一步,因为tabula只适用于pdfs。第二步是IMO从可视化信息中提取表数据的主要挑战,当您想了解一些算法方法时,检查那里的细节可能也很有趣。
https://stackoverflow.com/questions/31029734
复制相似问题