python之ddddocr快速识别

1. 安装模块

shell 复制代码
pip install ddddocr -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com

2. 编写代码

python 复制代码
import ddddocr  # 导入orc模块
import logging  # 导入日志
logging.getLogger().setLevel(logging.INFO)  # 设置日志级别
def ComputeCode(path):
    try:
        logging.info("数字字母验证码图片识别路径: %s", str(path))
        ocr = ddddocr.DdddOcr()  # 创建ocr对象
        with open(path, 'rb') as f: # 读取图片二进制字节
            img_bytes = f.read()
        res = ocr.classification(img_bytes) # 识别图片
        logging.info("数字字母验证码识别结果: %s", str(res))
        return res  # 返回结果
    except Exception as e:
        # 异常处理
        logging.exception("异常信息: %s", str(e))
        return None
ComputeCode("ocr.png")

注意:图片路径和命名不要含有中文路径,否则出现未知错误

3.附上测试图片

相关推荐
树码小子几秒前
综合练习:验证码案例(1)总体设计
java·开发语言·spring
草莓熊Lotso1 分钟前
Qt 主窗口核心组件实战:菜单栏、工具栏、状态栏、浮动窗口全攻略
运维·开发语言·人工智能·python·qt·ui
Ronin3052 分钟前
持久化数据管理中心模块
开发语言·c++·rabbitmq·gtest
froginwe112 分钟前
AJAX 实例详解
开发语言
魔力军3 分钟前
Rust学习Day2: 变量与可变性、数据类型和函数和控制流
开发语言·学习·rust
aiguangyuan5 分钟前
基于BiLSTM-CRF的命名实体识别模型:原理剖析与实现详解
人工智能·python·nlp
sycmancia5 分钟前
C++——强制类型转化、const的理解
开发语言·c++
hzb666666 分钟前
unictf2026
开发语言·javascript·安全·web安全·php
燃于AC之乐7 分钟前
深入解剖STL deque:从源码剖析到容器适配器实现
开发语言·c++·stl·源码剖析·容器实现
kaikaile19957 分钟前
基于MATLAB的滑动轴承弹流润滑仿真程序实现
开发语言·matlab