百度飞桨 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)

显示效果图

相关推荐
石榴树下的七彩鱼2 小时前
身份证 OCR 识别 API 接入详解(Python / Java 示例)
java·开发语言·人工智能·后端·python·ocr·api
ComputerInBook4 小时前
OpenCV图像处理——自适应阈值处理函数 adaptiveThreshold
图像处理·人工智能·opencv·自适应阈值处理
石榴树下的七彩鱼5 小时前
Python OCR 文字识别 API 接入完整教程
开发语言·人工智能·后端·python·ocr·api·图片识别
小陈phd8 小时前
多模态大模型学习笔记(三十五)——OCR全景认知:从字符识别到多模态理解的百年演进
笔记·学习·ocr
sali-tec8 小时前
C# 基于OpenCv的视觉工作流-章51-点查找
图像处理·人工智能·opencv·算法·计算机视觉
AI人工智能+8 小时前
文档抽取系统:OCR实现图像文本转换,结合大语言模型的语义理解能力,构建了高效的合同信息抽取系统
语言模型·自然语言处理·ocr·文档抽取
秋月的私语8 小时前
遥感影像拼接线优化工具:基于Qt+GDAL+OpenCV的从二到三实践
开发语言·qt·opencv
weixin_408099671 天前
python请求文字识别ocr api
开发语言·人工智能·后端·python·ocr·api·ocr文字识别
weixin_408099671 天前
【组合实战】OCR + 图片去水印 API:自动清洗图片再识别文字(完整方案 + 代码示例)
图像处理·后端·ocr·api·文字识别·去水印·ocr识别优化
yuan199971 天前
OpenCV ViBe 运动检测算法实现
人工智能·opencv·算法