diff --git a/DuplicateRemover.py b/DuplicateRemover.py index 97568e2..dc271ea 100644 --- a/DuplicateRemover.py +++ b/DuplicateRemover.py @@ -9,7 +9,7 @@ class DuplicateRemover: self.dirname = dirname self.hash_size = hash_size - def find_duplicates(self, verbose=True): + def find_duplicates(self, verbose=True, exportCSV=True): """ Find and Delete Duplicates """ @@ -21,14 +21,20 @@ class DuplicateRemover: print("Finding Duplicates Now!\n") for image in fnames: if list(image.lower().split('.'))[-1] in self.extensions: - with Image.open(os.path.join(self.dirname,image)) as img: - temp_hash = imagehash.average_hash(img, self.hash_size) - if temp_hash in hashes: - if verbose: - print("Duplicate {} \nfound for Image {}!\n".format(image,hashes[temp_hash])) - duplicates.append(image) - else: - hashes[temp_hash] = image + try: + with Image.open(os.path.join(self.dirname,image)) as img: + temp_hash = imagehash.average_hash(img, self.hash_size) + if temp_hash in hashes: + if verbose: + print("Duplicate {} \nfound for Image {}!\n".format(image,hashes[temp_hash])) + #if exportCSV: + # a = np.asarray([ image, hashes[temp_hash] ]) + # np.savetxt("duplicates.csv", a, delimiter=",") + duplicates.append(image) + else: + hashes[temp_hash] = image + except Exception as error: + print("Error: The following error occured:\n",image,"\n",error,"\n") if len(duplicates) != 0: if verbose: