How to detect tables in images using tesseract 4.0 or using pytesseract?

筅森魡賤 提交于 2019-12-22 09:56:45

问题


I want to detect tables in images. Identify the blocks of tables and possibly the text within it. In previous versions of tesseract, one could use the parameter textord_dump_table_image. How to extract tables in tesseract 4.0?


回答1:


It is quite bizarre that there is currently no API available to directly get table regions in tesseract. However you can use a small hack 'coughs' to get the table coordinates.

There is a configuration option textord_show_tables for tesseract. Set it to true using a config file or otherwise. Tesseract has a built-in capability to display its internal state, so that you can view its segmentation and recognition.

Build and install Viewer debugger for Tesseract . Refer ViewerDebugging

Instructions of its usage are also described in above link. It is a simple ServerSocket running on port 8461 which will open multiple windows when tesseract processes your image. You can view the detected tables in the window named 'Detected Tables'.

However most folks would be actually interested in getting the list of coordinates of tables. To achieve this you can write your own server socket listening on port 8461 and trick tesseract into sending messages to your server running locally. The messages sent to your server are in lua. These are instructions to setup and draw the GUI. You can write a simple parser that would interpret these instructions and extract out the coordinates. Most instructions are not of any use. Look out for when tesseract sends an instruction for creating a window named "Detected tables" or something similar. All the rectangles drawn in yellow color(255,255,0) are tables. So these are the instructions you actually care for. I would suggest dumping all the instructions in a file/console and see for yourself too.

PS: You might want to add interactive_display_mode 1 in your configuration settings. It prevents tesseract from closing before all instructions have been sent.

I acknowledge it is not an elegant solution, but works nevertheless.



来源:https://stackoverflow.com/questions/51626003/how-to-detect-tables-in-images-using-tesseract-4-0-or-using-pytesseract

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!