diff --git a/ppstructure/table/README.md b/ppstructure/table/README.md index 5ac99ac8588454a9d722211e9a46e2cef155873b..7ecbe0ad84207795fefcfa49775cbf4c8de69bf3 100644 --- a/ppstructure/table/README.md +++ b/ppstructure/table/README.md @@ -39,6 +39,8 @@ We evaluated the algorithm on the PubTabNet[1] eval dataset, and the ### 3.1 quick start +- table recognition + ```python cd PaddleOCR/ppstructure @@ -65,6 +67,24 @@ python3.7 table/predict_table.py \ After the operation is completed, the excel table of each image will be saved to the directory specified by the output field, and an html file will be produced in the directory to visually view the cell coordinates and the recognized table. +- table structure recognition +```python +cd PaddleOCR/ppstructure + +# download model +mkdir inference && cd inference +# Download the PP-Structurev2 form recognition model and unzip it +wget https://paddleocr.bj.bcebos.com/ppstructure/models/slanet/ch_ppstructure_mobile_v2.0_SLANet_infer.tar && tar xf ch_ppstructure_mobile_v2.0_SLANet_infer.tar +cd .. +# run +python3.7 table/predict_structure.py \ + --table_model_dir=inference/ch_ppstructure_mobile_v2.0_SLANet_infer \ + --table_char_dict_path=../ppocr/utils/dict/table_structure_dict_ch.txt \ + --image_dir=docs/table/table.jpg \ + --output=../output/table +``` +After the run is complete, the visualization of the detection frame of the cell will be saved to the directory specified by the output field. + ### 3.2 Train In this chapter, we only introduce the training of the table structure model, For model training of [text detection](../../doc/doc_en/detection_en.md) and [text recognition](../../doc/doc_en/recognition_en.md), please refer to the corresponding documents diff --git a/ppstructure/table/README_ch.md b/ppstructure/table/README_ch.md index a16de938a6f220e915237189c8c9b36088ccbf64..ac5029e7ff42d52bac51af1ccf0060511fbdb47c 100644 --- a/ppstructure/table/README_ch.md +++ b/ppstructure/table/README_ch.md @@ -49,6 +49,7 @@ ### 3.1 快速开始 +- 表格识别 ```python cd PaddleOCR/ppstructure @@ -61,7 +62,7 @@ wget https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_slim_infer # 下载PP-Structurev2表格识别模型并解压 wget https://paddleocr.bj.bcebos.com/ppstructure/models/slanet/ch_ppstructure_mobile_v2.0_SLANet_infer.tar && tar xf ch_ppstructure_mobile_v2.0_SLANet_infer.tar cd .. -# 执行预测 +# 执行表格识别 python3.7 table/predict_table.py \ --det_model_dir=inference/ch_PP-OCRv3_det_slim_infer \ --rec_model_dir=inference/ch_PP-OCRv3_rec_slim_infer \ @@ -73,6 +74,24 @@ python3.7 table/predict_table.py \ ``` 运行完成后,每张图片的excel表格会保存到output字段指定的目录下,同时在该目录下回生产一个html文件,用于可视化查看单元格坐标和识别的表格。 +- 表格结构识别 +```python +cd PaddleOCR/ppstructure + +# 下载模型 +mkdir inference && cd inference +# 下载PP-Structurev2表格识别模型并解压 +wget https://paddleocr.bj.bcebos.com/ppstructure/models/slanet/ch_ppstructure_mobile_v2.0_SLANet_infer.tar && tar xf ch_ppstructure_mobile_v2.0_SLANet_infer.tar +cd .. +# 执行表格结构识别 +python3.7 table/predict_structure.py \ + --table_model_dir=inference/ch_ppstructure_mobile_v2.0_SLANet_infer \ + --table_char_dict_path=../ppocr/utils/dict/table_structure_dict_ch.txt \ + --image_dir=docs/table/table.jpg \ + --output=../output/table +``` +运行完成后,单元格的检测框可视化会保存到output字段指定的目录下。 + ### 3.2 训练 diff --git a/ppstructure/table/predict_structure.py b/ppstructure/table/predict_structure.py index c4a816fd87d5608460ad62041d994ec744f1b6f1..7198fb2bcdc4d9d10f884f3a1545f23a1e628454 100755 --- a/ppstructure/table/predict_structure.py +++ b/ppstructure/table/predict_structure.py @@ -147,7 +147,10 @@ def main(args): f_w.write("result: {}, {}\n".format(structure_str_list, bbox_list_str)) - img = draw_rectangle(image_file, bbox_list) + if len(bbox_list) > 0 and len(bbox_list[0]) == 4: + img = draw_rectangle(image_file, pred_res['cell_bbox']) + else: + img = utility.draw_boxes(img, bbox_list) img_save_path = os.path.join(args.output, os.path.basename(image_file)) cv2.imwrite(img_save_path, img)