45 lines
1.1 KiB
Python
45 lines
1.1 KiB
Python
#-*- encoding:utf-8 -*-
|
|
|
|
'''
|
|
@Author : dingjiawen
|
|
@Date : 2023/12/12 13:30
|
|
@Usage :
|
|
@Desc :
|
|
'''
|
|
|
|
# -*- coding: UTF-8 -*-
|
|
from captcha.image import ImageCaptcha # pip install captcha
|
|
from PIL import Image
|
|
import random
|
|
import time
|
|
import setting
|
|
import os
|
|
|
|
|
|
def generate_captcha_text():
|
|
captcha_text = []
|
|
for i in range(setting.MAX_CAPTCHA):
|
|
c = random.choice(setting.ALL_CHAR_SET)
|
|
captcha_text.append(c)
|
|
return ''.join(captcha_text)
|
|
|
|
|
|
def generate_captcha_text_and_image():
|
|
image = ImageCaptcha()
|
|
captcha_text = generate_captcha_text()
|
|
captcha_image = Image.open(image.generate(captcha_text))
|
|
return captcha_text, captcha_image
|
|
|
|
|
|
if __name__ == '__main__':
|
|
# 生成3000张验证集
|
|
count = 3000
|
|
path = setting.PREDICT_DATASET_PATH
|
|
if not os.path.exists(path):
|
|
os.makedirs(path)
|
|
for i in range(count):
|
|
now = str(int(time.time()))
|
|
text, image = generate_captcha_text_and_image()
|
|
filename = text + '_' + now + '.png'
|
|
image.save(path + os.path.sep + filename)
|
|
print('saved %d : %s' % (i + 1, filename)) |