paddleocr报错解决方案汇总

一、安装注意事项

python不要超过10,尽量选8/9/10

二、快速开始

参考官方文档:https://paddlepaddle.github.io/PaddleOCR/main/ppstructure/quick_start.html#221

一般都要带方向识别,这里复制其中一段代码,防止官网挂掉

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

table_engine = PPStructure(show_log=True, image_orientation=True)

save_folder = './output'
img_path = 'ppstructure/docs/table/1.png'
img = cv2.imread(img_path)
result = table_engine(img)
save_structure_res(result, save_folder,os.path.basename(img_path).split('.')[0])

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

from PIL import Image

font_path = 'doc/fonts/simfang.ttf' # PaddleOCR下提供字体包
image = Image.open(img_path).convert('RGB')
im_show = draw_structure_result(image, result,font_path=font_path)
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')

三、paddleclas报错

使用方向分类要设置 image_orientation=True

按报错提示,安装 paddleclas,但是后续还是报错不存在,这里其实是安装文件本身的bug

参考:bugfix for deploy by TingquanGao · Pull Request #3313 · PaddlePaddle/PaddleClas · GitHub

一个是修改 deploy/utils/predictor.py,文件在虚拟环境里,可以通过 pip show paddleclas 来查看路径

将第58行-第62行

pd_version = 0
for v in paddle.__version__.split(".")[:3]:
    pd_version = 10 * pd_version + eval(v)

if pd_version == 0 or pd_version >= 260:

替换为

major_v, minor_v, _ = paddle.__version__.split(".")[:3]
major_v, minor_v = int(major_v), int(minor_v)
if (major_v == 0 and minor_v == 0) or (major_v >= 3):

另一个是 paddleclas.py

第49行

BASE_DIR = os.path.expanduser("~/.paddleclas/")

替换为

BASE_DIR = os.path.expanduser(os.path.join("~", ".paddleclas"))

测试正常

posted @ 2025-01-23 11:33  平底斜  阅读(1051)  评论(0)    收藏  举报