当前位置:网站首页>Generate verification code
Generate verification code
2022-04-23 17:58:00 【Feng Ye 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()
版权声明
本文为[Feng Ye 520]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230546152207.html
边栏推荐
- 云原生虚拟化:基于 Kubevirt 构建边缘计算实例
- .105Location
- Element calculation distance and event object
- Nat commun | current progress and open challenges of applied deep learning in Bioscience
- C1小笔记【任务训练篇一】
- Use of list - addition, deletion, modification and query
- Where is the configuration file of tidb server?
- 2022 Jiangxi Photovoltaic Exhibition, China Distributed Photovoltaic Exhibition, Nanchang Solar Energy Utilization Exhibition
- 31. Next arrangement
- JS forms the items with the same name in the array object into the same array according to the name
猜你喜欢
Implementation of k8s redis one master multi slave dynamic capacity expansion
Random number generation of C #
SystemVerilog (VI) - variable
Operators in C language
MySQL_ 01_ Simple data retrieval
MySQL advanced index [classification, performance analysis, use, design principles]
JS forms the items with the same name in the array object into the same array according to the name
C1小笔记【任务训练篇二】
Cross domain settings of Chrome browser -- including new and old versions
MySQL进阶之索引【分类,性能分析,使用,设计原则】
随机推荐
Dry goods | how to extract thumbnails quickly?
Summary of floating point double precision, single precision and half precision knowledge
JS interview question: FN call. call. call. Call (FN2) parsing
Halo open source project learning (II): entity classes and data tables
Eigen learning summary
Use of list - addition, deletion, modification and query
Realsense selection comparison d455 d435i d415 t265 3D hardware comparison
2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展
Go language JSON package usage
Halo open source project learning (II): entity classes and data tables
An example of linear regression based on tensorflow
Auto.js 自定义对话框
Compilation principle first set follow set select set prediction analysis table to judge whether the symbol string conforms to the grammar definition (with source code!!!)
列表的使用-增删改查
20222 return to the workplace
Fashion classification case based on keras
Future usage details
Commonly used functions -- spineros:: and spineros::)
Leak detection and vacancy filling (VIII)
Data stream encryption and decryption of C