代码拉取完成,页面将自动刷新
from paddleocr import PaddleOCR, draw_ocr
import cv2
import os
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
# 模型路径下必须含有model和params文件
ocr = PaddleOCR(use_angle_cls=True,
use_gpu=False,lang='ch') # det_model_dir='{your_det_model_dir}', rec_model_dir='{your_rec_model_dir}'
img_path = 'test_imgs/1.jpg'
img = cv2.imread(img_path)
import time
s = time.time()
result = ocr.ocr(img, cls=True)
print("result:",result)
print("time:",time.time()-s)
# 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:/paddle_pp/PaddleOCR/doc/simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result.jpg') # 结果图片保存在代码同级文件夹中。
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。