Created
February 2, 2019 20:32
-
-
Save lcrs/5f25dd1b12f0b01775d42a5b943afde4 to your computer and use it in GitHub Desktop.
check for matching images using perceptual hashing
This file contains 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 PIL import Image | |
import imagehash, os, sys | |
basenames1 = os.listdir(sys.argv[1]) | |
basenames2 = os.listdir(sys.argv[2]) | |
list1 = [] | |
list2 = [] | |
for (dirn, basen, lis) in ((sys.argv[1], basenames1, list1), (sys.argv[2], basenames2, list2)): | |
for fil in basen: | |
if(fil == '.DS_Store' or fil == 'Thumbs.db'): | |
continue | |
im = dirn + '/' + fil | |
hsh = imagehash.whash(Image.open(im)) | |
lis.append((im, hsh)) | |
html = open('o.html', 'w') | |
for (im, hsh) in list1: | |
html.write('<img src="%s" width=240 />' % im) | |
closest = None | |
dist = 99999 | |
for (im2, hsh2) in list2: | |
thisdist = hsh2 - hsh | |
if(thisdist < dist): | |
dist = thisdist | |
closest = im2 | |
html.write('<img src="%s" width=240 /><br /><br /><br />' % closest) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment