fromPILimportImageimportimagehashimportosfrompathlibimportPathfromtqdmimporttqdmdeffind_duplicate_images(input_folder, output_folder):
input_folder=Path(input_folder)
output_folder=Path(output_folder)
# Create the output folder if it doesn't existoutput_folder.mkdir(parents=True, exist_ok=True)
hash_dict= {}
# Iterate through all images in the input folderforimage_fileintqdm(input_folder.glob("*.png")):
withImage.open(image_file) asimg:
# Calculate the hash of the imageimg_hash=str(imagehash.average_hash(img))
# Check if the hash is already in the dictionaryifimg_hashnotinhash_dict:
# If not, save the image to the output folderhash_dict[img_hash] =image_fileimg.save(output_folder/image_file.name)
if__name__=="__main__":
input_folder='OUTPUT_FOLDER/frames_video_2/'output_folder="Duplicates/Frame2"# Replace with the desired output folder pathfind_duplicate_images(input_folder, output_folder)
print("Duplicate images removed successfully.")