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.附上测试图片

相关推荐
happy_0x3f7 分钟前
前端应用的离线暂停更新策略
开发语言·前端·php
2501_9095091020 分钟前
DAY 31
python
李昊哲小课28 分钟前
FastAPI 猫咖预约系统 API
人工智能·python·fastapi
shylyly_42 分钟前
C++中的类型转换
开发语言·c++·匿名对象·隐式类型转换·拷贝优化
你驴我44 分钟前
WhatsApp 消息撤回与编辑的幂等性设计实践
java·服务器·前端·后端·python
向日的葵0061 小时前
Redis会话机制vsJWT机制深度解析
数据库·redis·python·缓存·系统架构·jwt
祉猷并茂,雯华若锦1 小时前
Win下完美解决Allure报错,生成Web自动化测试报告
android·python·selenium·自动化
北冥you鱼1 小时前
Go 语言新手扫盲:指针 * 和 & 使用场景详解
开发语言·后端·golang
cui_ruicheng1 小时前
Python数据分析(一):数据分析概述与环境搭建
开发语言·python·数据分析