如何使用 tesseract 4.0 或使用 pytesseract 检测图像中的表格? [英] How to detect tables in images using tesseract 4.0 or using pytesseract?

查看:21
本文介绍了如何使用 tesseract 4.0 或使用 pytesseract 检测图像中的表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检测图像中的表格.识别表格块以及其中可能的文本.在之前版本的 tesseract 中,可以使用参数 textord_dump_table_image.如何在tesseract 4.0中提取表格?

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?

推荐答案

很奇怪,目前在 tesseract 中没有可直接获取表区域的 API.但是,您可以使用小技巧咳嗽"来获取表格坐标.

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.

tesseract 有一个配置选项 textord_show_tables.使用配置文件或其他方式将其设置为 true.Tesseract 内置了显示其内部状态的功能,以便您可以查看其分割和识别.

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.

为 Tesseract 构建和安装查看器调试器.参考 ViewerDebugging

Build and install Viewer debugger for Tesseract . Refer ViewerDebugging

上面的链接也描述了它的使用说明.它是一个运行在端口 8461 上的简单 ServerSocket,它会在 tesseract 处理您的图像时打开多个窗口.您可以在名为检测到的表"的窗口中查看检测到的表.

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'.

然而,大多数人实际上对获取表格坐标列表感兴趣.为此,您可以编写自己的服务器套接字,监听端口 8461,并欺骗 tesseract 将消息发送到本地运行的服务器.发送到您的服务器的消息在 lua 中.这些是设置和绘制 GUI 的说明.您可以编写一个简单的解析器来解释这些指令并提取出坐标.大多数说明没有任何用处.当 tesseract 发送指令以创建名为检测到的表"的窗口时,请注意.或类似的东西.所有以黄色(255,255,0)绘制的矩形都是表格.所以这些是您真正关心的说明.我建议将所有说明转储到文件/控制台中,并亲自查看.

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:您可能希望在配置设置中添加 interactive_display_mode 1.它可以防止 tesseract 在所有指令发送之前关闭.

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.

这篇关于如何使用 tesseract 4.0 或使用 pytesseract 检测图像中的表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆