zoukankan      html  css  js  c++  java
  • python的captcha验证码生成

    captcha不是一个单词而是一串单词的缩写 Completely Automated Public Turing Test to Tell Computers and Humans Apart(全自动区分计算机与人类的图灵测试)。我们都知道图灵测试是什么,captcha的核心思想就是设计出人类能够轻易通过但是计算机无法完成的任务,通过任务的测试结果,来确定进行操作的到底是人类还是计算机。

    生成验证码的代码如下:

    from captcha.image import ImageCaptcha
    import matplotlib.pyplot as plt
    import numpy as np
    import random
    import string
    
    characters = string.digits + string.ascii_lowercase
    print(characters)
    
    width, height, n_len, n_class = 170, 80, 4, len(characters)
    
    generator = ImageCaptcha(width=width, height=height)
    random_str = ''.join([random.choice(characters) for j in range(4)])
    img = generator.create_captcha_image(random_str, (0, 0, 153), (255, 255, 255))
    img.save("generate.png")
    img.show()
    plt.imshow(img)
    plt.title(random_str)

    但是想用这段代码生成与学校网站类似的代码,不过发现代码似乎有些问题,因为我再传颜色参数的时候发现并不准确,我传入(0,0,153)后获得的代码颜色并不是我要的蓝色,看了方法中的color举例用的就是(255,255,255),所以还是不深究了,自己直接取学校的代码自己手工清洗下数据,打好标签自己训练算了。

  • 相关阅读:
    【BZOJ 3709: [PA2014]Bohater】
    清北学堂2019.8.10 & 清北学堂2019.8.11 & 清北学堂2019.8.12
    清北学堂2019.8.9
    清北学堂2019.8.8
    清北学堂2019.8.7
    清北学堂2019.8.6
    【洛谷T89379 【qbxt】复读警告】
    【洛谷T89353 【BIO】RGB三角形】
    【洛谷T89359 扫雷】
    【洛谷P2016战略游戏】
  • 原文地址:https://www.cnblogs.com/gwklan/p/11305724.html
Copyright © 2011-2022 走看看