1 Star 0 Fork 1

Barneys/pytorch_captcha_recognition

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
captcha_gen.py 1.06 KB
一键复制 编辑 原始数据 按行查看 历史
Barneys 提交于 2021-12-11 13:49 +08:00 . 20211211
# -*- coding: UTF-8 -*-
from captcha.image import ImageCaptcha # pip install captcha
from PIL import Image
import random
import time
import captcha_setting
import os
def random_captcha():
captcha_text = []
for i in range(captcha_setting.MAX_CAPTCHA):
c = random.choice(captcha_setting.ALL_CHAR_SET)
captcha_text.append(c)
return ''.join(captcha_text)
# 生成字符对应的验证码
def gen_captcha_text_and_image():
image = ImageCaptcha()
captcha_text = random_captcha()
captcha_image = Image.open(image.generate(captcha_text))
return captcha_text, captcha_image
if __name__ == '__main__':
count = 5000
path = captcha_setting.TEST_DATASET_PATH #通过改变此处目录,以生成 训练、测试用的验证码集
if not os.path.exists(path):
os.makedirs(path)
for i in range(count):
now = str(int(time.time()))
text, image = gen_captcha_text_and_image()
filename = text+'_'+now+'.png'
image.save(path + os.path.sep + filename)
print('saved %d : %s' % (i+1,filename))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/Barneys/pytorch_captcha_recognition.git
git@gitee.com:Barneys/pytorch_captcha_recognition.git
Barneys
pytorch_captcha_recognition
pytorch_captcha_recognition
master

搜索帮助