Paddle ocr基本识别

卸载当前版本

pip uninstall paddlepaddle paddleocr paddlex -y

安装稳定版本

pip install paddlepaddle==3.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

pip install paddleocr==2.7.3 -i https://pypi.tuna.tsinghua.edu.cn/simple

例子:

python 复制代码
import sys
import os

os.environ['FLAGS_use_onednn'] = '0'
os.environ['PADDLE_PDX_DISABLE_MODEL_SOURCE_CHECK'] = 'True'

import paddle
print(f"PaddlePaddle version: {paddle.__version__}")

from paddleocr import PaddleOCR
import cv2
import numpy as np

# 初始化 PaddleOCR (PaddleOCR 3.x API)
ocr = PaddleOCR(
    lang='ch',
    use_textline_orientation=True
)

# 方法1: 识别图片文件
img_path = 'd:/123.png'

try:

    result = ocr.ocr(img_path)

    # 只打印识别的文本
    texts = []
    if result is not None:
        for res in result:
            if res is not None and len(res) > 0:
                for word_info in res:
                    if isinstance(word_info, dict):
                        text = word_info.get('text', '')
                        texts.append(text)
                    elif isinstance(word_info, (list, tuple)) and len(word_info) >= 2:
                        text = word_info[1][0] if isinstance(word_info[1], (list, tuple)) else word_info[1]
                        texts.append(text)
    
    if texts:
        print('\n'.join(texts))
    else:
        print("未识别到任何文本")
        
except Exception as e:
    print(f"错误: {e}")
    import traceback
    traceback.print_exc()
相关推荐
学术 学术 Fun1 小时前
612 次图表重建实验告诉我们的:O612 次图表重建实验告诉我们的:OCR、图形与连接线CR、图形与连接线
机器学习·计算机视觉·ocr·图表
天远Date Lab8 小时前
零信任架构实战:基于天远行驶OCR证识别构建自动化高并发物流车队准入网关
人工智能·架构·自动化·ocr
梦想的颜色3 天前
OCR 识别原理与 Python 识图全实战:从文字提取到图像内容理解
python·计算机视觉·ocr·图像识别·python 识图
楚识科技3 天前
信创 OCR 四关:芯片/OS/加速卡/合规全适配实践
ocr
天远Date Lab3 天前
零信任架构实战:基于天远车信盟出险构建自动化汽车消费贷合规网关
人工智能·机器学习·计算机视觉·ocr
AI人工智能+3 天前
证件阅读机,通过光学扫描、AI大脑、芯片感应三双“眼睛”协同工作,借助深度学习OCR引擎完成证卡识别与结构化输出
深度学习·ocr·智能硬件·证件阅读机
天远数科4 天前
零信任架构实战:基于天远身份证OCR构建自动化高并发移动支付网关
人工智能·架构·自动化·ocr
聚美智数4 天前
机动车登记证书 OCR 识别-绿本信息结构化提取-车辆登记证书识别-机动车证件 OCR 解析 API 接口介绍
ocr
yychen_java4 天前
从像素到汉字:基于深度学习的中文OCR系统六步全链路剖析
人工智能·深度学习·ocr