{"id":18273601,"url":"https://github.com/rapidai/tablestructurerec","last_synced_at":"2025-04-13T16:45:09.413Z","repository":{"id":207997834,"uuid":"717361718","full_name":"RapidAI/TableStructureRec","owner":"RapidAI","description":"整理目前开源的最优表格识别模型，完善前后处理，模型转换为ONNX     Organize the currently open-source optimal table recognition models, improve pre-processing and post-processing, and convert the models to ONNX.","archived":false,"fork":false,"pushed_at":"2025-03-31T14:49:21.000Z","size":10764,"stargazers_count":625,"open_issues_count":2,"forks_count":53,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-04-06T14:01:41.710Z","etag":null,"topics":["ocr","structure","table","table-recognition"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RapidAI.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":"https://raw.githubusercontent.com/RapidAI/.github/6db6b6b9273f3151094a462a61fbc8e88564562c/assets/Sponsor.png"}},"created_at":"2023-11-11T08:37:11.000Z","updated_at":"2025-04-06T13:50:11.000Z","dependencies_parsed_at":"2024-06-14T01:54:53.770Z","dependency_job_id":"58dcd832-c4c4-421e-a6ef-0329bd7315cc","html_url":"https://github.com/RapidAI/TableStructureRec","commit_stats":{"total_commits":102,"total_committers":4,"mean_commits":25.5,"dds":"0.37254901960784315","last_synced_commit":"b2accc25f471366f89c4851f7d226fec54fa240a"},"previous_names":["rapidai/tablestructurerec"],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RapidAI%2FTableStructureRec","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RapidAI%2FTableStructureRec/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RapidAI%2FTableStructureRec/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RapidAI%2FTableStructureRec/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RapidAI","download_url":"https://codeload.github.com/RapidAI/TableStructureRec/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248748506,"owners_count":21155644,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ocr","structure","table","table-recognition"],"created_at":"2024-11-05T12:07:01.334Z","updated_at":"2025-04-13T16:45:09.358Z","avatar_url":"https://github.com/RapidAI.png","language":"Python","readme":"\u003cdiv align=\"center\"\u003e\n  \u003cdiv align=\"center\"\u003e\n    \u003ch1\u003e\u003cb\u003e📊 表格结构识别\u003c/b\u003e\u003c/h1\u003e\n  \u003c/div\u003e\n  \u003ca href=\"\"\u003e\u003cimg src=\"https://img.shields.io/badge/Python-\u003e=3.6,\u003c3.12-aff.svg\"\u003e\u003c/a\u003e\n  \u003ca href=\"\"\u003e\u003cimg src=\"https://img.shields.io/badge/OS-Linux%2C%20Mac%2C%20Win-pink.svg\"\u003e\u003c/a\u003e\n\u003ca href=\"https://pypi.org/project/lineless-table-rec/\"\u003e\u003cimg alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/lineless-table-rec\"\u003e\u003c/a\u003e\n\u003ca href=\"https://pepy.tech/project/lineless-table-rec\"\u003e\u003cimg src=\"https://static.pepy.tech/personalized-badge/lineless-table-rec?period=total\u0026units=abbreviation\u0026left_color=grey\u0026right_color=blue\u0026left_text=Downloads%20Lineless\"\u003e\u003c/a\u003e\n\u003ca href=\"https://pepy.tech/project/wired-table-rec\"\u003e\u003cimg src=\"https://static.pepy.tech/personalized-badge/wired-table-rec?period=total\u0026units=abbreviation\u0026left_color=grey\u0026right_color=blue\u0026left_text=Downloads%20Wired\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://semver.org/\"\u003e\u003cimg alt=\"SemVer2.0\" src=\"https://img.shields.io/badge/SemVer-2.0-brightgreen\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/psf/black\"\u003e\u003cimg src=\"https://img.shields.io/badge/code%20style-black-000000.svg\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/RapidAI/TableStructureRec/blob/c41bbd23898cb27a957ed962b0ffee3c74dfeff1/LICENSE\"\u003e\u003cimg alt=\"GitHub\" src=\"https://img.shields.io/badge/license-Apache 2.0-blue\"\u003e\u003c/a\u003e\n\n[English](README_en.md) | 简体中文 \n\u003c/div\u003e\n\n### 最近更新\n- **2024.12.25**\n    - 补充文档扭曲矫正/去模糊/去阴影/二值化方案，可作为前置处理 [RapidUnDistort](https://github.com/Joker1212/RapidUnWrap)\n- **2025.1.9**\n  - RapidTable支持了 unitable 模型，精度更高支持torch推理，补充测评数据\n- **2025.3.30**\n    - 输入输出格式对齐RapidTable\n    - 支持模型自动下载\n    - 增加来自paddle的新表格分类模型\n    - 增加最新PaddleX表格识别模型测评值\n    - 支持 rapidocr 2.0 取消重复ocr检测\n    \n### 简介\n💖该仓库是用来对文档中表格做结构化识别的推理库，包括来自阿里读光有线和无线表格识别模型，llaipython(微信)贡献的有线表格模型，网易Qanything内置表格分类模型等。\\\n[快速开始](#安装) [模型评测](#指标结果) [使用建议](#使用建议) [单字匹配](#单字ocr匹配) [文档扭曲修正](https://github.com/Joker1212/RapidUnWrap) [表格旋转及透视修正](#表格旋转及透视修正) [输入参数](#核心参数) [常见问题](#FAQ) [更新计划](#更新计划)\n#### 特点\n\n⚡  **快**  采用ONNXRuntime作为推理引擎，cpu下单图推理1-7s\n\n🎯 **准**: 结合表格类型分类模型，区分有线表格，无线表格，任务更细分，精度更高\n\n🛡️ **稳**: 不依赖任何第三方训练框架，只依赖必要基础库，避免包冲突\n\n### 在线演示\n[modelscope魔塔](https://www.modelscope.cn/studios/RapidAI/TableRec)\n[huggingface](https://huggingface.co/spaces/Joker1212/TableDetAndRec)\n### 效果展示\n\n\u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"https://github.com/RapidAI/TableStructureRec/releases/download/v0.0.0/demo_img_output.gif\" alt=\"Demo\" width=\"100%\" height=\"100%\"\u003e\n\u003c/div\u003e\n\n### 指标结果\n\n[TableRecognitionMetric 评测工具](https://github.com/SWHL/TableRecognitionMetric) [huggingface数据集](https://huggingface.co/datasets/SWHL/table_rec_test_dataset) [modelscope 数据集](https://www.modelscope.cn/datasets/jockerK/TEDS_TEST/files) [Rapid OCR](https://github.com/RapidAI/RapidOCR)\n\n测试环境: ubuntu 20.04 python 3.10.10 opencv-python 4.10.0.84 \n\n注:\n   StructEqTable 输出为 latex，只取成功转换为html并去除样式标签后进行测评\n\n   Surya-Tabled 使用内置ocr模块，表格模型为行列识别模型，无法识别单元格合并，导致分数较低\n\n| 方法                                                                                                       |    TEDS     | TEDS-only-structure |\n|:---------------------------------------------------------------------------------------------------------|:-----------:|:-----------------:|\n| [surya-tabled(--skip-detect)](https://github.com/VikParuchuri/tabled)                                    |   0.33437   |       0.65865     |\n| [surya-tabled](https://github.com/VikParuchuri/tabled)                                                   |   0.33940   |       0.67103     |\n| [deepdoctection(table-transformer)](https://github.com/deepdoctection/deepdoctection?tab=readme-ov-file) |   0.59975   |       0.69918     |\n| [ppstructure_table_master](https://github.com/PaddlePaddle/PaddleOCR/tree/main/ppstructure)              |   0.61606   |       0.73892     |\n| [ppsturcture_table_engine](https://github.com/PaddlePaddle/PaddleOCR/tree/main/ppstructure)              |   0.67924   |       0.78653     |\n| [StructEqTable](https://github.com/UniModal4Reasoning/StructEqTable-Deploy)                              |   0.67310   |       0.81210     |\n| [RapidTable(SLANet)](https://github.com/RapidAI/RapidTable)                                              |   0.71654   |       0.81067     |\n| table_cls + wired_table_rec v1 + lineless_table_rec                                                      |   0.75288   |       0.82574     |\n| table_cls + wired_table_rec v2 + lineless_table_rec                                                      |   0.77676   |       0.84580     |\n| [PaddleX(SLANetXt+RT-DERT)](https://github.com/PaddlePaddle/PaddleX)                                                                            |   0.79900   |       **0.92222**     |\n| [RapidTable(SLANet-plus)](https://github.com/RapidAI/RapidTable)                                         |   0.84481   |       0.91369     |\n| [RapidTable(unitable)](https://github.com/RapidAI/RapidTable)                                            | **0.86200** |     0.91813     |\n\n### 使用建议\nwired_table_rec_v2(有线表格精度最高): 通用场景有线表格(论文，杂志，期刊, 收据，单据，账单)\n\nwired_table_rec_v2 对1500px内大小的图片效果最好，所以分辨率超过2000px建议等比缩放一下\n\nSLANet-plus/unitable (综合精度最高): 文档场景表格(论文，杂志，期刊中的表格)\n\n### 安装\nrapidocr2.0以上版本支持torch,onnx,paddle,openvino等多引擎切换，详情参考[rapidocr文档](https://rapidai.github.io/RapidOCRDocs/main/install_usage/rapidocr/usage/)\n``` python {linenos=table}\npip install wired_table_rec lineless_table_rec table_cls\npip install rapidocr \n```\n\n### 快速使用\n\u003e ⚠️注意：在`wired_table_rec/table_cls`\u003e=1.2.0` `lineless_table_rec` \u003e 0.1.0 后，采用同RapidTable完全一致格式的输入输出\n``` python {linenos=table}\nfrom pathlib import Path\n\nfrom wired_table_rec.utils.utils import VisTable\nfrom table_cls import TableCls\nfrom wired_table_rec.main import WiredTableInput, WiredTableRecognition\nfrom lineless_table_rec.main import LinelessTableInput, LinelessTableRecognition\nfrom rapidocr import RapidOCR\n\n\nif __name__ == \"__main__\":\n    # Init\n    wired_input = WiredTableInput()\n    lineless_input = LinelessTableInput()\n    wired_engine = WiredTableRecognition(wired_input)\n    lineless_engine = LinelessTableRecognition(lineless_input)\n    viser = VisTable()\n    # 默认小yolo模型(0.1s)，可切换为精度更高yolox(0.25s),更快的qanything(0.07s)模型或paddle模型(0.03s)\n    table_cls = TableCls()\n    img_path = f\"tests/test_files/table.jpg\"\n\n    cls, elasp = table_cls(img_path)\n    if cls == \"wired\":\n        table_engine = wired_engine\n    else:\n        table_engine = lineless_engine\n\n    # 使用RapidOCR输入\n    ocr_engine = RapidOCR()\n    rapid_ocr_output = ocr_engine(img_path, return_word_box=True)\n    ocr_result = list(\n        zip(rapid_ocr_output.boxes, rapid_ocr_output.txts, rapid_ocr_output.scores)\n    )\n    table_results = table_engine(\n        img_path, ocr_result=ocr_result\n    )\n\n    # 使用单字识别\n    # word_results = rapid_ocr_output.word_results\n    # ocr_result = [\n    #     [word_result[2], word_result[0], word_result[1]] for word_result in word_results\n    # ]\n    # table_results = table_engine(\n    #     img_path, ocr_result=ocr_result, enhance_box_line=False\n    # )\n\n    # Save\n    # save_dir = Path(\"outputs\")\n    # save_dir.mkdir(parents=True, exist_ok=True)\n    # \n    # save_html_path = f\"outputs/{Path(img_path).stem}.html\"\n    # save_drawed_path = f\"outputs/{Path(img_path).stem}_table_vis{Path(img_path).suffix}\"\n    # save_logic_path = (\n    #     f\"outputs/{Path(img_path).stem}_table_vis_logic{Path(img_path).suffix}\"\n    # )\n\n    # Visualize table rec result\n    # vis_imged = viser(\n    #     img_path, table_results, save_html_path, save_drawed_path, save_logic_path\n    # )\n\n\n\n\n\n```\n\n#### 单字ocr匹配\n\n```python\n# 将单字box转换为行识别同样的结构)\nfrom rapidocr import RapidOCR\nimg_path = \"tests/test_files/wired/table4.jpg\"\nocr_engine = RapidOCR()\nrapid_ocr_output = ocr_engine(img_path, return_word_box=True)\nword_results = rapid_ocr_output.word_results\nocr_result = [\n    [word_result[2], word_result[0], word_result[1]] for word_result in word_results\n]\n```\n\n#### 表格旋转及透视修正\n##### 1.简单背景，小角度场景\n最新wiredV2模型自适应小角度旋转\n```python\nimport cv2\n\nimg_path = f'tests/test_files/wired/squeeze_error.jpeg'\nfrom wired_table_rec.utils import ImageOrientationCorrector\n\nimg_orientation_corrector = ImageOrientationCorrector()\nimg = cv2.imread(img_path)\nimg = img_orientation_corrector(img)\ncv2.imwrite(f'img_rotated.jpg', img)\n```\n##### 2.复杂背景，多表格场景\n需要gpu或更高精度场景，请参考项目[RapidTableDet](https://github.com/RapidAI/RapidTableDetection)\n```python\npip install rapid-table-det\n```\n```python\nimport os\nimport cv2\nfrom rapid_table_det.utils import img_loader, visuallize, extract_table_img\nfrom rapid_table_det.inference import TableDetector\ntable_det = TableDetector()\nimg_path = f\"tests/test_files/chip.jpg\"\nresult, elapse = table_det(img_path)\nimg = img_loader(img_path)\nextract_img = img.copy()\n#可能有多表格\nfor i, res in enumerate(result):\n    box = res[\"box\"]\n    lt, rt, rb, lb = res[\"lt\"], res[\"rt\"], res[\"rb\"], res[\"lb\"]\n    # 带识别框和左上角方向位置\n    img = visuallize(img, box, lt, rt, rb, lb)\n    # 透视变换提取表格图片\n    wrapped_img = extract_table_img(extract_img.copy(), lt, rt, rb, lb)\n#     cv2.imwrite(f\"{out_dir}/{file_name}-extract-{i}.jpg\", wrapped_img)\n# cv2.imwrite(f\"{out_dir}/{file_name}-visualize.jpg\", img)\n```\n\n### 核心参数\n```python\n# 输入(WiredTableInput/LinelessTableInput)\n@dataclass\nclass WiredTableInput:\n    model_type: Optional[str] = \"unet\" #unet/cycle_center_net\n    model_path: Union[str, Path, None, Dict[str, str]] = None\n    use_cuda: bool = False\n    device: str = \"cpu\"\n    \n@dataclass\nclass LinelessTableInput:\n    model_type: Optional[str] = \"lore\" #lore\n    model_path: Union[str, Path, None, Dict[str, str]] = None\n    use_cuda: bool = False\n    device: str = \"cpu\"\n    \n# 输出(WiredTableOutput/LinelessTableOutput)\n@dataclass\nclass WiredTableOutput:\n    pred_html: Optional[str] = None\n    cell_bboxes: Optional[np.ndarray] = None\n    logic_points: Optional[np.ndarray] = None\n    elapse: Optional[float] = None\n    \n@dataclass\nclass LinelessTableOutput:\n    pred_html: Optional[str] = None\n    cell_bboxes: Optional[np.ndarray] = None\n    logic_points: Optional[np.ndarray] = None\n    elapse: Optional[float] = None\n```\n\n```python\nwired_table_rec = WiredTableRecognition(WiredTableInput())\ntable_results = wired_table_rec(\n    img, # 图片 Union[str, np.ndarray, bytes, Path, PIL.Image.Image]\n    ocr_result, # 输入rapidOCR识别结果，不传默认使用内部rapidocr模型\n    enhance_box_line=True, # 识别框切割增强(关闭避免多余切割，开启减少漏切割)，默认为True\n    col_threshold=15, # 识别框左边界x坐标差值小于col_threshold的默认同列\n    row_threshold=10, # 识别框上边界y坐标差值小于row_threshold的默认同行\n    rotated_fix=True, # wiredV2支持，轻度旋转(-45°~45°)矫正，默认为True\n    need_ocr=True, # 是否进行OCR识别, 默认为True\n)\nlineless_table_rec = LinelessTableRecognition(LinelessTableInput())\ntable_results = lineless_table_rec(\n    img, # 图片 Union[str, np.ndarray, bytes, Path, PIL.Image.Image]\n    ocr_result, # 输入rapidOCR识别结果，不传默认使用内部rapidocr模型\n    need_ocr=True, # 是否进行OCR识别, 默认为True\n)\n```\n\n\n## FAQ\n1. **问：识别框丢失了内部文字信息**\n   - 答：默认使用的rapidocr小模型，如果需要更高精度的效果，可以从 [模型列表](https://rapidai.github.io/RapidOCRDocs/model_list/#_1)\n   下载更高精度的ocr模型,在执行时传入ocr_result即可, \n   - 或者尝试调节rapid_ocr的参数, 根据在线demo调节参数， [modelscope](https://www.modelscope.cn/studios/liekkas/RapidOCRDemo/summary) [huggingface](https://huggingface.co/spaces/SWHL/RapidOCRDemo)\n     然后在推理时传入即可\n2. **问：文档扭曲变形怎么处理？**\n    - 答：使用 [RapidUnwrap](https://github.com/Joker1212/RapidUnWrap)\n3. **问：模型支持 gpu 加速吗？**\n    - 答：目前表格模型的推理非常快，有线表格在100ms级别，无线表格在500ms级别，\n      主要耗时在ocr阶段，可以参考 [rapidocr_paddle](https://rapidai.github.io/RapidOCRDocs/install_usage/rapidocr_paddle/usage/#_3)\n      加速ocr识别过程\n\n### 更新计划\n\n- [x] 图片小角度偏移修正方法补充\n- [x] 增加数据集数量，增加更多评测对比\n- [x] 补充复杂场景表格检测和提取，解决旋转和透视导致的低识别率\n- [x] 优化表格分类器\n- [ ] 优化无线表格模型\n\n### 处理流程\n\n```mermaid\nflowchart TD\n    A[/表格图片/] --\u003e B([表格分类 table_cls])\n    B --\u003e C([有线表格识别 wired_table_rec]) \u0026 D([无线表格识别 lineless_table_rec]) --\u003e E([文字识别 rapidocr])\n    E --\u003e F[/html结构化输出/]\n```\n\n### 致谢\n\n[PaddleX 表格识别](https://github.com/PaddlePaddle/PaddleX/blob/release/3.0-beta1/docs/module_usage/tutorials/ocr_modules/table_structure_recognition.md)\n\n[PaddleOCR 表格识别](https://github.com/PaddlePaddle/PaddleOCR/blob/4b17511491adcfd0f3e2970895d06814d1ce56cc/ppstructure/table/README_ch.md)\n\n[读光-表格结构识别-有线表格](https://www.modelscope.cn/models/damo/cv_dla34_table-structure-recognition_cycle-centernet/summary)\n\n[读光-表格结构识别-无线表格](https://www.modelscope.cn/models/damo/cv_resnet-transformer_table-structure-recognition_lore/summary)\n\n[Qanything-RAG](https://github.com/netease-youdao/QAnything)\n\n非常感谢 llaipython(微信，提供全套有偿高精度表格提取) 提供高精度有线表格模型。\n\n非常感谢 [MajexH](https://github.com/MajexH)完成deepdoctection(rag-flow)的表格识别测试\n\n### 贡献指南\n\n欢迎提交请求。对于重大更改，请先打开issue讨论您想要改变的内容。\n\n请确保适当更新测试。\n\n### [赞助](https://rapidai.github.io/Knowledge-QA-LLM/docs/sponsor/)\n\n如果您想要赞助该项目，可直接点击当前页最上面的Sponsor按钮，请写好备注(**您的Github账号名称**)，方便添加到赞助列表中。\n\n### 开源许可证\n\n该项目采用[Apache 2.0](https://github.com/RapidAI/TableStructureRec/blob/c41bbd23898cb27a957ed962b0ffee3c74dfeff1/LICENSE)\n开源许可证。\n","funding_links":["https://raw.githubusercontent.com/RapidAI/.github/6db6b6b9273f3151094a462a61fbc8e88564562c/assets/Sponsor.png"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frapidai%2Ftablestructurerec","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frapidai%2Ftablestructurerec","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frapidai%2Ftablestructurerec/lists"}