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()
相关推荐
满怀冰雪8 小时前
08-Paddle 神经网络层入门:Linear、激活函数与 Sequential
神经网络·机器学习·paddle
小保CPP10 小时前
OpenCV C++基于极值区域滤波算法的场景文本检测(OCR)
c++·人工智能·opencv·算法·计算机视觉·ocr
白驹_过隙10 小时前
【大模型OCR落地终极排坑:OvisOCR2+vLLM从报错到批量稳定部署全过程】
人工智能·ocr·vllm
蓝创工坊Blue Foundry1 天前
PaddleOCR 本地部署教程:小模型 OCR 如何完成字段提取到 Excel
pdf·自动化·ocr·excel·paddlepaddle·paddle
满怀冰雪1 天前
09-使用 paddle.nn 构建第一个多层感知机
python·深度学习·神经网络·paddle
蓝创工坊Blue Foundry2 天前
个人藏书太多怎么整理?用 OCR 字段提取汇总成电子书目
pdf·ocr·excel·文心一言·paddlepaddle·paddle
小保CPP2 天前
OpenCV C++校正AI模型检测到的文本(OCR)
c++·人工智能·opencv·计算机视觉·ocr
开开心心就好2 天前
Word双击预览图片插件弥补Word功能缺失
人工智能·python·智能手机·ocr·电脑·word·音视频
蓝创工坊Blue Foundry2 天前
扫描件批量转 Excel:先确认要整表还原还是字段汇总
python·pdf·ocr·excel
审小匠OpenCPAi3 天前
审计票据与财报 PDF 怎么识别?通用 OCR、表格结构识别与多模态大模型的精度对比
pdf·ocr·审计