Ejemplo n.º 1
0
def compare(target):
    target = handle_name(target)
    image_png = Image.open(READ_CAPTCHA_PATH + target + '.png')
    matched_diff = sys.maxsize
    match = ''
    match_pos = None

    for i, (captcha_name, captcha_image) in enumerate(
            break_captcha(READ_CAPTCHA_PATH, target, image_png)):
        for name, image in list_individual_images(PATH_EXISTENT):
            if target not in handle_name(name):
                continue
            captcha_part = READ_CAPTCHA_PATH + captcha_name + '_' + str(
                i) + '.png'
            existent_image_path = PATH_EXISTENT + name
            diff = compare_image(existent_image_path, captcha_part)
            if diff < matched_diff:
                matched_diff = diff
                match = existent_image_path
                match_pos = i

    return match_pos
Ejemplo n.º 2
0
# coding: utf-8
from PIL import Image
import math
import os
from utils import list_individual_images, break_captcha, save_candidate_name

READ_PATH = './src/images/'
SAVE_PATH = './src/images_tmp/'

if __name__ == '__main__':
    for name, image in list_individual_images(READ_PATH):
        lst = enumerate(break_captcha(READ_PATH, name, image))
        for i, (icon_name, captcha_image) in lst:
            save_candidate_name(SAVE_PATH, captcha_image, icon_name, i)
Ejemplo n.º 3
0
if __name__ == '__main__':
    try:
        target = sys.argv[1]
    except IndexError:
        print('You need to specify a target')
        print('python3 compare_images.py <icon-name>')
        sys.exit()

    image_png = Image.open('./images/' + target + '.png')
    matched_diff = sys.maxsize
    match = ''
    match_pos = None

    for i, (captcha_name, captcha_image) in enumerate(
            break_captcha(READ_CAPTCHA_PATH, target, image_png)):
        for name, image in list_individual_images(PATH_EXISTENT):
            if remove_accents(target) not in remove_accents(name):
                continue
            captcha_part = READ_CAPTCHA_PATH + captcha_name + '_' + str(
                i) + '.png'
            existent_image_path = PATH_EXISTENT + name
            diff = compare_image(existent_image_path, captcha_part)
            if diff < matched_diff:
                matched_diff = diff
                match = existent_image_path
                match_pos = i

    # print(matched_diff, match, match_pos)
    print(match_pos)