VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • 机器视觉(4)--生成验证码

用python生成验证码,为后期训练自己的模型做准备

复制代码
import numpy as py
from captcha.image import ImageCaptcha
import  os

number = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']

def random_Caption_text(char_set=number, captcha_size=4):
    captcha_text = []
    for i in range(captcha_size):
        # 随机选择
        c = py.random.choice(char_set)
        captcha_text.append(c)
    return captcha_text


def Get_captcha_text_To_image():
    image = ImageCaptcha()
    # 随机获取验证码
    random_num = random_Caption_text()
    #     把验证码转换为字符串
    captcha_text = ''.join(random_num)
    #     生成验证码
    captcha = image.generate(captcha_text)
    image.write(captcha_text, 'C:/Users/Administrator/Desktop/image/captcha/' + captcha_text + '.jpg')

def main():

    for i in range(1000):
        Get_captcha_text_To_image()



if __name__ == '__main__':
    main()
复制代码

测试结果:


相关教程