Created
October 9, 2016 04:55
-
-
Save mhluska/450cce89a41eaa8a3c03b6cd9c567be1 to your computer and use it in GitHub Desktop.
Quick and dirty script to match similar images using image_match
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from image_match.goldberg import ImageSignature | |
import glob | |
BASE_DIR='/Users/maros.hluska/Dropbox' | |
BASE_IMAGE='./crop.png' | |
gis = ImageSignature() | |
def filenames(extension): | |
return glob.iglob(BASE_DIR + '/**/*.' + extension, recursive=True) | |
def match(extension): | |
paths = filenames(extension) | |
total = str(len(list(paths))) | |
paths = filenames(extension) | |
for index, filename in enumerate(paths): | |
print('Checking image ' + str(index + 1) + '/' + total + ' ' + filename) | |
try: | |
a = gis.generate_signature(BASE_IMAGE) | |
b = gis.generate_signature(filename) | |
if gis.normalized_distance(a, b) < 0.40: | |
print('MATCH!') | |
print(filename) | |
# Works around the follwing error: | |
# ValueError: Could not load "" | |
# Reason: "image file is truncated (49 bytes not processed)" | |
except ValueError: | |
pass | |
match('jpg') | |
match('png') | |
match('gif') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment