使用PaddleOCR进行文字识别
安装
pip install paddleocr
测试
import cv2
import numpy as np
from paddleocr import PaddleOCR
ocr = PaddleOCR(use_angle_cls=True)
image_path = 'test.jpg'
img = cv2.imread(image_path)
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_gray1 = img_gray[:,:, np.newaxis]
img_gray3 = np.concatenate([img_gray1, img_gray1, img_gray1], axis=-1)
texts = ocr.ocr(img_gray3)
for text in texts:
"""
box 坐标1 坐标2
坐标4 坐标3
"""
box = text[0]
t = text[1][0]
score = text[1][1]
可视化(图像上画出文本和得分) import os import shutil import cv2 import numpy as np import uuid from PIL import ImageFo