from paddleocr import PaddleOCR, draw_ocr
import time
import cv2
from PIL import Image
import numpy as np
# Paddleocr目前支持的多语言语种可以通过修改lang参数进行切换# 例如`ch`, `en`, `fr`, `german`, `korean`, `japan`# ocr = PaddleOCR(use_angle_cls=True, lang="en",use_gpu=False)
ocr = PaddleOCR(det_model_dir="F:\myproject\PaddleOCR-release-2.6\output\db_mv3",use_angle_cls=True, lang="ch",use_gpu=False)
img_path="GZDT22-019020_right_up_camImg_45.jpg"# 显示结果# 如果本地没有simfang.ttf,可以在doc/fonts目录下下载#方法一
image = Image.open(img_path).convert("RGB")
image=image.rotate(90)
image1=image.transpose(Image.FLIP_LEFT_RIGHT)# image1.save('result112.jpg')
image1=np.array(image1)
result = ocr.ocr(image1, det=True)print("result:",result)for idx inrange(len(result)):
res = result[idx]for line in res:print("line:",line)
boxes =[line[0]for line in result]print("boxes:",boxes)
txts =[line[1][0]for line in result]print("txts:",txts)
scores =[line[1][1]for line in result]print("scores:",scores)
im_show = draw_ocr(image, boxes, txts, scores, font_path='doc/fonts/simfang.ttf')
im_show = Image.fromarray(im_show)
im_show.save('result1.jpg')#方法二print("**********************************************************")
img=cv2.imread(img_path)
img1=cv2.flip(img,0)
result = ocr.ocr(img1, det=True)print("result:",result)for idx inrange(len(result)):
res = result[idx]for line in res:print("line:",line)
boxes =[line[0]for line in result]print("boxes:",boxes)
txts =[line[1][0]for line in result]print("txts:",txts)
scores =[line[1][1]for line in result]print("scores:",scores)
im_show = draw_ocr(img1, boxes, txts, scores, font_path='doc/fonts/simfang.ttf')
cv2.imwrite("result2.jpg",im_show)