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

相关推荐
CappuccinoRose11 分钟前
前端开发交互体系 - 汇总篇
开发语言·前端·javascript·css·html·交互
tryCbest28 分钟前
Python 爬虫从入门到实战(二):进阶篇——反爬对抗、并发与动态页面
开发语言·爬虫·python
VIP_CQCRE29 分钟前
GPT Image 2.6 动态表情交付别只发预览:GIF 文件校验、哈希清单与下载排错
图像处理·人工智能·python·gif
2601_9679873735 分钟前
使用 NumPy 和 Python 实现梯度下降
python·机器学习·线性回归·numpy·梯度下降
BD_Marathon1 小时前
Jupyter魔法命令
ide·python·jupyter
S_WEAN1 小时前
【C++】STL - Priority_queue的使用及模拟实现与仿函数
开发语言·c++
词却1 小时前
Python 正则表达式实战:使用 re 模块提取符合条件的字符串
python·正则表达式
星落梦生2 小时前
Tlias前端案例涉及知识点 (14)
开发语言·前端·javascript
汤姆宝库2 小时前
视觉语言模型的实现:LLaVA式投影与指令微调
python·深度学习·语言模型
2601_9679791212 小时前
初学者必知的Python中优雅的用法
python·枚举·初学者·优雅用法·字典解析