作者:du-qhy | 来源:互联网 | 2023-06-27 12:20
可以直接使用pip安装PaddleOCR库pipinstallpaddleocr代码示例:frompaddleocrimportPaddleOCR,draw_ocr
可以直接使用pip安装PaddleOCR库
pip install paddleocr
代码示例:
from paddleocr import PaddleOCR, draw_ocr
# 模型路径下必须含有model和params文件
ocr = PaddleOCR(use_angle_cls=True,use_gpu=False)#det_model_dir='{your_det_model_dir}', rec_model_dir='{your_rec_model_dir}', rec_char_dict_path='{your_rec_char_dict_path}', cls_model_dir='{your_cls_model_dir}', use_angle_cls=True
img_path = 'D:/E/mypic/ocr2.jpg'
result = ocr.ocr(img_path, cls=True)
for line in result:print(line)# 显示结果
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='D:/E/paddle_pp/PaddleOCR/doc/simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg')
结果如下: