Paddle OCR 中英文检测识别 - python 实现

DataBall 助力快速掌握数据集的信息和使用方式,会员享有 百种数据集,持续增加中。

需要更多数据资源和技术解决方案,知识星球: "DataBall - X 数据球(free)"

-----------------------------------------------------------------

Paddle OCR 中英文检测识别

具体实现代码如下:

python 复制代码
#-*-coding:utf-8-*-
# date:2024-12-22
# Author: DataBall - XIAN
# Function:  OCR 检测识别

import os
import cv2
import numpy as np
import time
from paddleocr import PaddleOCR

if __name__ == '__main__':

    if False: # 中文
        cls_model_dir='paddleModels/whl/cls/ch_ppocr_mobile_v2.0_cls_infer'
        rec_model_dir='paddleModels/whl/rec/ch/ch_PP-OCRv4_rec_infer'
        ocr = PaddleOCR(use_angle_cls=True, lang="ch", det=False,cls_model_dir=cls_model_dir,rec_model_dir=rec_model_dir)  # need to run only once to download and load model into memory
    else: # 英文
        # ocr = PaddleOCR(use_angle_cls=True, lang="en")
        cls_model_dir='paddleModels/whl/cls/en_ppocr_mobile_v2.0_cls_infer'
        rec_model_dir='paddleModels/whl/rec/ch/en/en_PP-OCRv4_rec_infer'
        ocr = PaddleOCR(use_angle_cls=True, lang="en", det=False,cls_model_dir=cls_model_dir,rec_model_dir=rec_model_dir)  # need to run only once to download and load model into memory
    img_path = "image/2.png"
    img = cv2.imread(img_path)
    result_det = ocr.ocr(img, cls=True)

    print(type(result_det))
    result_det = result_det[0]
    idx_ = 0
    for m_ in result_det:
        idx_ += 1
        bbox_,contant_ = m_
        print("[{}] bbox: {}, contant: {}".format(idx_,bbox_,contant_))
        pts = np.array(bbox_).astype(np.int32)
        pts = pts.reshape((-1,1,2))
        # 绘制区域
        cv2.polylines(img,[pts],True,(255,22,150),1)

    cv2.namedWindow("img",0)
    cv2.imshow("img",img)
    cv2.waitKey(0)
    cv2.imwrite("out.png",img)

示例如下:

​​​​​​

助力快速掌握数据集的信息和使用方式。

数据可以如此美好!

相关推荐
Lethehong4 分钟前
openEuler AI 图像处理:Stable Diffusion CPU 推理性能优化与评测
人工智能
Guheyunyi8 分钟前
智慧停车管理系统:以科技重塑交通效率与体验
大数据·服务器·人工智能·科技·安全·生活
std860219 分钟前
微软将允许用户从Windows 11文件资源管理器中移除“AI 动作”入口
人工智能·microsoft
为爱停留12 分钟前
Spring AI实现MCP(Model Context Protocol)详解与实践
java·人工智能·spring
秋刀鱼 ..12 分钟前
第七届国际科技创新学术交流大会暨机械工程与自动化国际学术会议(MEA 2025)
运维·人工智能·python·科技·机器人·自动化
cici1587413 分钟前
基于不同算法的数字图像修复Matlab实现
算法·计算机视觉·matlab
学历真的很重要7 小时前
VsCode+Roo Code+Gemini 2.5 Pro+Gemini Balance AI辅助编程环境搭建(理论上通过多个Api Key负载均衡达到无限免费Gemini 2.5 Pro)
前端·人工智能·vscode·后端·语言模型·负载均衡·ai编程
普通网友7 小时前
微服务注册中心与负载均衡实战精要,微软 2025 年 8 月更新:对固态硬盘与电脑功能有哪些潜在的影响。
人工智能·ai智能体·技术问答
苍何7 小时前
一人手搓!AI 漫剧从0到1详细教程
人工智能
苍何7 小时前
Gemini 3 刚刷屏,蚂蚁灵光又整活:一句话生成「闪游戏」
人工智能