问题:
代码:
# 先是输入图像
# https://github.com/PaddlePaddle/PaddleOCR/blob/dygraph/ppstructure/table/predict_table.py#L55
from table.predict_table import TableSystem,to_excel
from utility import init_args
import cv2
import pandas as pd
# 初始化参数
args = init_args().parse_args(args=[])
args.det_model_dir='./inference/ch_PP-OCRv2_det_infer'
args.rec_model_dir='./inference/ch_PP-OCRv2_rec_infer'
args.table_model_dir='./inference/en_ppocr_mobile_v2.0_table_structure_infer'
args.image_dir='.//home/aistudio/22.jpg'
args.rec_char_dict_path='../ppocr/utils/ppocr_keys_v1.txt'
args.table_char_dict_path='../ppocr/utils/dict/table_structure_dict.txt'
args.det_limit_side_len=736
args.det_limit_type='min'
args.output='../output/table'
args.use_gpu=False
# 初始化表格识别系统
table_sys = TableSystem(args)
img = cv2.imread('./22.jpg')
# 执行表格识别
pred_html = table_sys(img)
#pf1=pd.DataFrame(pred_html)
print(type(pred_html))
print('pred_html内容',pred_html)
# 结果存储到excel文件
to_excel(pred_html,'./22.xlsx')
# print(pred_html)
报错:
AttributeError: ‘dict’ object has no attribute 'strip
问题原因:
to_excel时只能是html结构,需要将输入数据类型进行转换。输入数据类型为dict,装为html,需要转为string类型即可。
解决:
改为:
to_excel(str(pred_html),'./22.xlsx')