Skip to content
This repository has been archived by the owner on Mar 23, 2020. It is now read-only.
/ Captchatool Public archive

用于识别各种普通验证码的工具模块

Notifications You must be signed in to change notification settings

MMMzq/Captchatool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Captcha-tool

用于识别普通验证码的工具类

安装

  • 环境要求: python3
  • **点击我**把项目克隆或直接下载
  • 在项目目录下输入命令 pip3 install -r r-cpu.txt或者是pip3 install -r r-gpu.txt,后者会安装tensorflow-gpu版本.(强烈推荐gpu版本,gpu版本会在模型训练时会比cpu版本快很多,但是会多了一些安装步骤,具体请百度)

使用

  • 导入模块
    from cnn_code_tool import Code_tool
  • 创建类
    ct=Code_tool(charset,model_path,train_path,test_path,label_resolve)
    # charset 验证码的所有字符集
    # model_path 模型路径,训练完后模型将会保存在此路径下,推测验证码时模型将会从该路径下导入模型
    # train_path 训练数据路径,模型训练时使用
    # test_path 测试数据路径,模型训练时使用
    # label_resolve 从文件名解析出标签的函数,模型训练时使用
  • 训练模型
    ct.train()
  • 训练完后推测验证码
    captcha=ct.infer_file('captcha_img_filename') # 导入并推测验证码图片的验证码

帮助

  • 上面的使用说明已经是一个完整的例子了,更多运行例子可以运行项目demo,我已经添加了大量注释来说明
  • 一般完成一个验证码的识别的过程有如下步骤
    • 手工打码,把打码后的图片,放到训练路径下,测试图片同理(一般对于只含数字和26个字母长度为4的验证来说,并且可以切割出一个个字符的话,500~1000张打码后的图片即可达到0.8左右的命中率,如果不能分割的话一般需要几千张图片来训练模型)
    • 数据准备好后创建Code_tool类调用train()方法训练模型
    • 模型训练完后,一般调用infer_file()或者infer_bytes()来推测验证码,infer_file()用于从文件导入数据来推测其验证码,infer_bytes()一般用于网络获取验证码的字节对象后直接推测其验证码,例如使用requests库请求验证码后马上推测其验证码
        r=requests.get('获取验证码的url')
        captcha=ct.infer_bytes(r.content)
        print(captcha) # 打印模型推测的验证码
  • 值得注意的是推测的图片要和模型训练时的图片的宽度,高度,通道,格式要完全一致
  • 更多详尽说明点击跳转

About

用于识别各种普通验证码的工具模块

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages