Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PPStructure.save_structure_res设置return_ocr_result_in_table=True JSON报错 #8611

Closed
zealzeng opened this issue Dec 13, 2022 · 1 comment
Assignees

Comments

@zealzeng
Copy link

pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
pip install "paddleocr>=2.6.0.3" -i https://mirror.baidu.com/pypi/simple
pip install paddleclas>=2.4.3 -i https://mirror.baidu.com/pypi/simple

官方例子, 主要是修改了result = table_engine(img, True)想获取返回的字符

import os
import cv2
from paddleocr import PPStructure, draw_structure_result, save_structure_res

table_engine = PPStructure(show_log=True)
save_folder = './output'
img_path = './doc/table/table.jpg'
img = cv2.imread(img_path)
result = table_engine(img, True)
save_structure_res(result, save_folder, os.path.basename(img_path).split('.')[0])

for line in result:
    line.pop('img')
    print(line)

具体报错如下:

Traceback (most recent call last):
  File "D:\project\pp-structure\main.py", line 12, in <module>
    save_structure_res(result, save_folder, os.path.basename(img_path).split('.')[0])
  File "D:\project\pp-structure\venv\lib\site-packages\paddleocr\ppstructure\predict_system.py", line 199, in save_structure_res
    f.write('{}\n'.format(json.dumps(region)))
  File "D:\Python\Python39\lib\json\__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "D:\Python\Python39\lib\json\encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "D:\Python\Python39\lib\json\encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "D:\Python\Python39\lib\json\encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type ndarray is not JSON serializable

ndarray json dump的出错了, 默认table_engine(img)没问题

@andyjiang1116
Copy link
Collaborator

感谢反馈,已经修复 PR,可以更新到2.6.1.2试试,或者手动编译安装试试

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants