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()
相关推荐
深圳市快瞳科技有限公司4 小时前
人车准入审核的工程实现:证件OCR、联网查验与业务决策
计算机视觉·ocr·vin码查询·车辆证件ocr·车辆信息查验·汽车ocr
开开心心就好10 小时前
白天晚上自动调蓝光,护眼工具亮度可调
服务器·开发语言·算法·pdf·ocr·intellij-idea·idea
开开心心就好13 小时前
安卓PDF处理工具,免费无广告零弹窗
android·服务器·开发语言·算法·pdf·ocr
开开心心就好2 天前
多份文档怎么批量打印?支持多种格式
java·服务器·开发语言·pdf·ocr·散列表·启发式算法
开开心心就好2 天前
文件被占用删不掉?解锁工具强制删除
java·运维·服务器·开发语言·前端·pdf·ocr
SamChan903 天前
PDF 翻译后 1,250 变成 1.250,是错了吗?用 Python 核对数字格式
python·pdf·ocr·数据校验·文档翻译
开开心心就好3 天前
打印机卡住打不了?一键清理卡死打印队列
服务器·开发语言·算法·pdf·ocr·idea·visual studio code
聚美智数4 天前
印章识别-合同印章识别-票据印章OCR-印章文字识别-电子印章检测-印章编码识别
ocr
神奇的代码在哪里4 天前
没有独显也能跑多模态:MiniCPM-V 4.7-1B 本地 OCR 实测(附源码)
ocr·多模态大模型·llama.cpp·gguf·minicpm-v
科小怪4 天前
图片里的文字复制不了?Umi-OCR 免费离线工具解压就能用
ocr