赞
踩
pip install ddddocr -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
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")
注意:图片路径和命名不要含有中文路径,否则出现未知错误
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。