Giter Site home page Giter Site logo

学习素材怎么准备 about dddd_trainer HOT 2 OPEN

sml2h3 avatar sml2h3 commented on June 21, 2024
学习素材怎么准备

from dddd_trainer.

Comments (2)

26038874 avatar 26038874 commented on June 21, 2024

还有一个疑问,使用默认的模型识别率很低,如果重新训练是只能用自己后面打算识别的这些素材,还是可以去下载其他素材

from dddd_trainer.

sxueck avatar sxueck commented on June 21, 2024

一个简单的示例,生成10万张长度为4-6的包含数字和大小写字符串的验证码图片

from captcha.image import ImageCaptcha
import numpy as np
from PIL import Image
import random
import os
import hashlib

number = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
            'v', 'w', 'x', 'y', 'z']
ALPHABET = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
            'V', 'W', 'X', 'Y', 'Z']


def random_captcha_text(char_set=None, captcha_size=None):
    if char_set is None:
        char_set = number + alphabet + ALPHABET
    if captcha_size is None:
        captcha_size = random.randint(4, 6)  # 随机长度从4到6
    captcha_text = random.choices(char_set, k=captcha_size)
    return captcha_text


def gen_captcha_text_and_image():
    # 随机选择难度参数,例如图片宽度和高度
    width, height = random.randint(100, 200), random.randint(50, 100)
    image = ImageCaptcha(width=width, height=height)

    captcha_text = random_captcha_text()
    captcha_text = ''.join(captcha_text)

    hash_obj = hashlib.sha256(captcha_text.encode('utf-8'))
    hash_hex = hash_obj.hexdigest()
    filename = f"{captcha_text}_{hash_hex}.jpg"
    file_path = os.path.join("dist", filename)

    captcha = image.generate(captcha_text)
    # 写到文件
    with open(file_path, 'wb') as f:
        f.write(captcha.getbuffer())

    captcha_image = Image.open(captcha)
    captcha_image = np.array(captcha_image)
    return captcha_text, captcha_image


if __name__ == '__main__':
    if not os.path.exists('dist'):
        os.makedirs('dist')

    for _ in range(100000):
        gen_captcha_text_and_image()

from dddd_trainer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.