from paddleocr import PaddleOCR, draw_ocr
# https://github.com/PaddlePaddle/PaddleOCR
# https://blog.51cto.com/u_16175475/6823894
# https://blog.csdn.net/weixin_45897172/article/details/131406224
# Paddleocr目前支持的多语言语种可以通过修改lang参数进行切换
# 例如`ch`, `en`, `fr`, `german`, `korean`, `japan`
ocr = PaddleOCR(use_angle_cls=True, lang="ch") # need to run only once to download and load model into memory
img_path = './data/短剧场.jpg'
result = ocr.ocr(img_path, cls=True)
for idx in range(len(result)):
res = result[idx]
for line in res:
print(line[1][0])
name = line[1][0]
if name in result_dict.keys():
print(result_dict[name])
# 显示结果
# 如果本地没有simfang.ttf,可以在doc/fonts目录下下载
from PIL import Image
result = result[0]
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='doc/fonts/simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('./data/result.jpg')
paddleocr的使用方式
最新推荐文章于 2024-02-05 15:38:50 发布