python的captcha验证码生成

今天药忘吃喽~ 2021-10-30 02:26 455阅读 0赞

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

生成验证码的代码如下:

  1. from captcha.image import ImageCaptcha
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. import random
  5. import string
  6. characters = string.digits + string.ascii_lowercase
  7. print(characters)
  8. width, height, n_len, n_class = 170, 80, 4, len(characters)
  9. generator = ImageCaptcha(width=width, height=height)
  10. random_str = ''.join([random.choice(characters) for j in range(4)])
  11. img = generator.create_captcha_image(random_str, (0, 0, 153), (255, 255, 255))
  12. img.save("generate.png")
  13. img.show()
  14. plt.imshow(img)
  15. plt.title(random_str)

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

转载于:https://www.cnblogs.com/gwklan/p/11305724.html

发表评论

表情:
评论列表 (有 0 条评论,455人围观)

还没有评论,来说两句吧...

相关阅读