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
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 if __name__ == '__main__': try: target = handle_name(sys.argv[1]).lower() except IndexError: print('You need to specify a target') print('python3 compare_images.py <icon-name>') sys.exit() print(compare(target))
matches = sorted(matches, key=lambda val: val.distance) score = sum([i.distance for i in matches]) return score def compare_image(image1, image2): img1 = cv2.imread(image1, cv2.IMREAD_GRAYSCALE) img2 = cv2.imread(image2, cv2.IMREAD_GRAYSCALE) diff = calculate_diff(img1, img2) return diff if __name__ == '__main__': try: target = handle_name(sys.argv[1]).lower() 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 target not in handle_name(name): continue