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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With