1.ddddocr-模块安装
pip install ddddocr
2.python实际使用案例
import ddddocr
ocr=ddddocr.DdddOcr()
with open('test_img.png', 'rb') as f:
img_bytes=f.read()
res=ocr.classification(img_bytes)
print(res)
普通干扰较弱的验证码均可识别通过
实用案例:
import os
import random
import requests
import ddddocr
def picture_verif():
math = random.random()
url = f'https://---脱敏处理-----VerifyCode?k=CuoMy8eR4mvVZNqbnNd8K9QOV8KYc465&r={math}'
print(url)
headers = {
'User-Agent':'给你自己的ua'
}
path = os.getcwd() + '/picture.jpg'
print(path)
res = requests.get(url=url,headers=headers)
# 图片保存到本地-对照识别结果验证使用
with open(path,'wb') as f:
f.write(res.content)
ocr = ddddocr.DdddOcr()
# 不用读取本地图片,直接识别源码
res = ocr.classification(res.content)
print(res)
return res