百度飞桨 OCR识别

百度飞桨 OCR识别代码

python 复制代码
import warnings
import time
import cv2 as cv
import paddlehub as hub
# Load the image
img = cv.imread("1.jpg")
height, width, channels = img.shape
imglist = [img]
ocr = hub.Module(name="ch_pp-ocrv3", enable_mkldnn=True)  # mkldnn acceleration is only effective on CPU
start_time = time.time()
result = ocr.recognize_text(images=imglist)
end_time = time.time()
elapsed_time = end_time - start_time
print(f"执行时间: {elapsed_time} seconds")
for data in result[0]['data']:
    text = data['text']
    confidence = data['confidence']
    if confidence > 0.85:
        points = data['text_box_position']
        left = min(point[0] for point in points)
        top = min(point[1] for point in points)
        right = max(point[0] for point in points)
        bottom = max(point[1] for point in points)
        print(f"Text: {text}, Box: ({left}, {top}), ({right}, {bottom})")
        cv.rectangle(img, (left, top), (right, bottom), (0,0, 255), 2)
        cv.putText(img, text, (left, top - 10), cv.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255), 2)
resize_img = cv.resize(img, [width // 4, height // 4])
cv.imwrite("result.jpg", resize_img)
cv.imshow("Result",resize_img)
cv.waitKey(0)
cv.destroyAllWindows()
print(result)

显示效果图

相关推荐
没了对象省了流量ii3 小时前
本地高精度OCR!由GPT-4o-mini驱动的开源OCR!
ocr
菜狗woc8 小时前
opencv-python的简单练习
人工智能·python·opencv
paixiaoxin10 小时前
CV-OCR经典论文解读|An Empirical Study of Scaling Law for OCR/OCR 缩放定律的实证研究
人工智能·深度学习·机器学习·生成对抗网络·计算机视觉·ocr·.net
西猫雷婶10 小时前
python学opencv|读取图像(十四)BGR图像和HSV图像通道拆分
开发语言·python·opencv
云空10 小时前
《QT 5.14.1 搭建 opencv 环境全攻略》
开发语言·qt·opencv
编码小哥10 小时前
opencv中的色彩空间
opencv·计算机视觉
吃个糖糖11 小时前
34 Opencv 自定义角点检测
人工智能·opencv·计算机视觉
花花少年11 小时前
【Windows版】opencv 和opencv_contrib配置
opencv·opencv_contrib
YRr YRr11 小时前
解决Ubuntu 20.04上编译OpenCV 3.2时遇到的stdlib.h缺失错误
linux·opencv·ubuntu
葡萄爱13 小时前
OpenCV图像分割
人工智能·opencv·计算机视觉