飞浆paddleocr识别

1 安装 PaddlePaddle

有显卡的:
python3 -m pip install paddlepaddle-gpu
没显卡的:
python3 -m pip install paddlepaddle

1.2 安装PaddleOCR Whl包

pip install paddleocr

调用

2.1 命令行使用

中英文模型
检测、方向分类识别:设置参数--use_gpu false禁用gpu设备
paddleocr --image_dir ./imgs_en/img_12.jpg --use_angle_cls true --lang ch --use_gpu false
输出将是一个列表,每个项目包含边界框、文本和识别置信度

[[[441.0, 174.0], [1166.0, 176.0], [1165.0, 222.0], [441.0, 221.0]], ('ACKNOWLEDGEMENTS', 0.9971134662628174)]
[[[403.0, 346.0], [1204.0, 348.0], [1204.0, 384.0], [402.0, 383.0]], ('We would like to thank all the designers and', 0.9761400818824768)]
[[[403.0, 396.0], [1204.0, 398.0], [1204.0, 434.0], [402.0, 433.0]], ('contributors who have been involved in the', 0.9791957139968872)]
......

2.2 程序调用

from paddleocr import PaddleOCR,draw_ocr
# Paddleocr supports Chinese, English, French, German, Korean and Japanese.
# You can set the parameter `lang` as `ch`, `en`, `fr`, `german`, `korean`, `japan`
# to switch the language model in order.
ocr = PaddleOCR(use_angle_cls=True, lang='en') # need to run only once to download and load model into memory
img_path = './imgs_en/img_12.jpg'
result = ocr.ocr(img_path, cls=True)
for line in result:
    print(line)


# draw result
from PIL import Image
image = Image.open(img_path).convert('RGB')
boxes = [line[0] for line in result]
txts = [line[1][0] for line in result]
scores = [line[1][1] for line in result]
im_show = draw_ocr(image, boxes, txts, scores, font_path='./fonts/simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')

更多详细,参见原文

posted on 2022-05-20 16:15  耀扬  阅读(513)  评论(0编辑  收藏  举报

导航