参考github的官网就可以:
github链接
简单的说,就是两句话:
python3 -m pip install paddlepaddle-gpu -i https://mirror.baidu.com/pypi/simple
pip install "paddleocr>=2.0.1" # 推荐使用2.0.1+版本
from paddleocr import PaddleOCR
import cv2
import numpy as np
if __name__=="__main__":
ocr = PaddleOCR(use_angle_cls=True, use_gpu=True,ocr_version='PP-OCRv4')
img_path = r'F:\dataset\images\1.bmp'
img=cv2.imread(img_path)
result = ocr.ocr(img, cls=True)[0]
for line in result:
list_points=line[0]
str_data,conf=line[1]
pts = np.array(list_points, np.int32)
pts = pts.reshape((-1, 1, 2))
cv2.polylines(img, [pts], isClosed=True, color=(0, 255, 255), thickness=1)
cv2.imshow("img",img)
cv2.waitKey(0)
如果想对每一个字符都做框选,可以多写几句画,把每个框都拆出来。
from paddleocr import PaddleOCR
import cv2
import numpy as np
def getm(p):
res=math.sqrt(p[0]*p[0]+p[1]*p[1])
return res
if __name__=="__main__":
ocr = PaddleOCR(use_angle_cls=True, use_gpu=True,ocr_version='PP-OCRv4')
img_path = r'F:\dataset\images\1.bmp'
img=cv2.imread(img_path)
result = ocr.ocr(img, cls=True)[0]
for line in result:
list_points=line[0]
str_data,conf=line[1]
len_str=len(str_data)
p0,p1,p2,p3=np.array(list_points)
if getm(p0-p1)