当前位置:网站首页>生成验证码
生成验证码
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
边栏推荐
猜你喜欢
随机推荐
8. Integer Decomposition
Feign请求日志统一打印
Rust 的多线程安全引用 Arc
从源代码到可执行文件的过程
程序設計訓練
Import of data
Conversion between JS object and string
9.Life, the Universe, and Everything
The onnx model of yolov5 removes the transfer layer
用C语言实现重写strcmp等四个函数
[transfer] MySQL: how many rows of data can InnoDB store in a B + tree?
[leetcode 202] happy number
进程间通信的方式
Basic knowledge of network in cloud computing
P1586 solution to tetragonal theorem
[leetcode 59] spiral matrix II
解决ArcGIS分区统计显示太多唯一值执行失败
[leetcode 6] zigzag transformation
11.a==b?
Database - sorting data