Exemplo n.º 1
0
def get_train_word_lens_data(count):

    logger.info('Start get train word lens')

    X_train = []
    Y_train = []

    fn_lst = get_fn_lst(conf.CAPTCHA_SRC_DIR)

    num = 0
    for fn in fn_lst[:count]:

        word = get_word_from_fn(fn)

        image = get_image(fn)

        train_image = get_word_train_image(image)

        X_train.append([train_image])

        Y_train.append(len(word))

        num += 1
        if num % 1000 == 0:
            logger.info('Get train word lens: complete %s', num)

    imsave('/opt/data/log_train_word_lens_data' + conf.CAPTCHA_EXTENSION,
           X_train[0][0])

    return X_train, Y_train
Exemplo n.º 2
0
def make_letters_from_all():
    for index, fn in enumerate(get_fn_lst(conf.CAPTCHA_SRC_DIR)):

        word = get_word_from_fn(fn)

        word_len = len(word)

        image = get_image(fn)

        word_image = get_word_image_for_letters(image)

        try:
            letter_images = make_letters(word_image, word_len)
        except LettersError:
            continue

        for p in range(word_len):

            letter = word[p]
            letter_folder = conf.CAPTCHA_TRAIN_DIR + letter.encode('utf-8') + '/'

            try:
                os.mkdir(letter_folder)
            except OSError:
                pass

            letter_image = letter_images[p]

            letter_fn = letter_folder + str(p) + '-' + word.encode('utf-8') + conf.CAPTCHA_EXTENSION

            imsave(letter_fn, letter_image)

        if index % 100 == 0:
            logger.info('Process on image: %s', index)
Exemplo n.º 3
0
def get_train_letters_data(count):
    X_train = []
    Y_train = []

    logger.info('Start get train letters')

    sorted_letters_folders_lst = filter(
        lambda l: len(l.decode('utf-8')) == 1,
        sorted(os.listdir(conf.CAPTCHA_TRAIN_DIR)))

    letters_folders_lst = list(enumerate(sorted_letters_folders_lst))

    random.shuffle(letters_folders_lst)

    for num, letter in letters_folders_lst:

        letter_folder = conf.CAPTCHA_TRAIN_DIR + letter + '/'

        letters_fn_lst = os.listdir(letter_folder)

        random.shuffle(letters_fn_lst)

        for fn in letters_fn_lst[:count]:
            letter_fn = letter_folder + fn

            image = get_image(letter_fn)

            train_image = get_letter_train_image(image)

            X_train.append([train_image])

            Y_train.append(num)

        imsave('/opt/data/log_train_letter_image' + conf.CAPTCHA_EXTENSION,
               train_image)

        logger.info('Get train letters %s: complete %s', letter, num)

    return X_train, Y_train