当前位置:网站首页>生成验证码
生成验证码
2022-04-23 05:47:00 【峰爷520】
from captcha.image import ImageCaptcha
import random
import numpy as np
from PIL import Image
import matplotlib.pyplot as plt
number = ['0','1','2','3','4','5','6','7','8','9']
ALPH = []
alph = []
for i in range(65,91):
ALPH.append(chr(i))
for i in ALPH:
alph.append(i.swapcase())
def random_captcha_text(size=4,charset=number+alph+ALPH):
captcha_text = []
for i in range(size):
c = random.choice(charset)
captcha_text.append(c)
return captcha_text
def gen_captcha_image():
image = ImageCaptcha()
captcha_text = random_captcha_text()
captcha_text = ''.join(captcha_text)
captchaInfo = image.generate(captcha_text)
# print(captchaInfo)
captcha_image = Image.open(captchaInfo)
captcha_image = np.array(captcha_image)
return captcha_text,captcha_image
if __name__ == '__main__':
text, image = gen_captcha_image()
print(text)
# print(image)
f = plt.figure()
ax = f.add_subplot(111)
ax.text(0.1, 0.9, text, ha='center',va='center')
plt.imshow(image)
plt.show()
版权声明
本文为[峰爷520]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_41752427/article/details/81086449
边栏推荐
猜你喜欢
随机推荐
P1018 maximum product solution
[leetcode 202] happy number
xlsxwriter.exceptions.FileCreateError: [Errno 13] Permission denied问题
[leetcode 383] ransom letter
如何安装jsonpath包
Cf1427c the hard work of paparazzi
Qthread simple test understanding
Basic knowledge of network in cloud computing
A solution to replace not in in SQL
Log4j2跨线程打印traceId
Usage scenario of copyonwritearraylist
Common sense of thread pool
用C语言实现重写strcmp等四个函数
爬取小米有品app商品数据
Mysql database foundation
Rust 中的指针:Box、Rc、Cell、RefCell
Flask操作多个数据库
Addition, deletion, modification and query of MySQL table
Example of reentrant lock thread waiting to wake up
Completely clean up MySQL win