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)

示例如下:

​​​​​​

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

数据可以如此美好!

相关推荐
孟祥_成都3 小时前
【全网最通俗!新手到AI全栈开发必读】 AI 是如何进化到大模型的
前端·人工智能·全栈
牛奶3 小时前
AI辅助开发的基础概念
前端·人工智能·ai编程
东坡肘子3 小时前
OpenClaw 不错,但我好像没有那么需要 -- 肘子的 Swift 周报 #125
人工智能·swiftui·swift
风象南11 小时前
普通人用AI加持赚到的第一个100块
人工智能·后端
牛奶11 小时前
2026年大模型怎么选?前端人实用对比
前端·人工智能·ai编程
牛奶11 小时前
前端人为什么要学AI?
前端·人工智能·ai编程
罗西的思考14 小时前
AI Agent框架探秘:拆解 OpenHands(10)--- Runtime
人工智能·算法·机器学习
冬奇Lab15 小时前
OpenClaw 源码精读(2):Channel & Routing——一条消息如何找到它的 Agent?
人工智能·开源·源码阅读
冬奇Lab15 小时前
一天一个开源项目(第38篇):Claude Code Telegram - 用 Telegram 远程用 Claude Code,随时随地聊项目
人工智能·开源·资讯
格砸16 小时前
从入门到辞职|从ChatGPT到OpenClaw,跟上智能时代的进化
前端·人工智能·后端