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

相关推荐
CodeDevMaster11 分钟前
在Jupyter Notebook中使用Conda虚拟环境
python·jupyter
wkj00117 分钟前
接口实现类向上转型和向上转型解析
java·开发语言·c#
冷月半明22 分钟前
告别手动拖动!Python+dddocr自动化破解多缺口滑块
python
Kusunoki_D25 分钟前
Python 实现 Web 静态服务器(HTTP 协议)
服务器·前端·python
寒士obj1 小时前
类加载的过程
java·开发语言
无名之逆1 小时前
大三自学笔记:探索Hyperlane框架的心路历程
java·开发语言·前端·spring boot·后端·rust·编程
站大爷IP1 小时前
当Python遇上多线程:ThreadPoolExecutor的实用指南
python
站大爷IP1 小时前
Python文件操作的“保险箱”:with语句深度实战指南
python
探模之翼1 小时前
高效管理Python环境:Miniforge、pyenv和Poetry深度对比与应用
python
hweiyu001 小时前
tomcat指定使用的jdk版本
java·开发语言·tomcat