当前位置:网站首页>生成验证码
生成验证码
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
边栏推荐
猜你喜欢
随机推荐
ArcGIS表转EXCEL超出上限转换失败
D. Optimal partition segment tree optimization DP
[leetcode217] there are duplicate elements
Rust:如何实现一个线程池?
实现一个计算m~n(m<n)之间所有整数的和的简单函数
Log4j2跨线程打印traceId
[leetcode169] most elements
Excel打开超大csv格式数据
GNU EFI header file
根据SQL语句查询出的结果集,将其封装为json
[transfer] MySQL: how many rows of data can InnoDB store in a B + tree?
Calculation (enter the calculation formula to get the result)
线程和进程的关系和区别是什么
多线程爬取马可波罗网供应商数据
渔网道路密度计算
几行代码教你爬取LOL皮肤图片
[leetcode 202] happy number
[leetcode 954] double pair array
Sakura substring thinking
检测技术与原理









