Many students may have such troubles , You want to delete similar pictures in your own folder , But there are too many pictures , So manual deletion is a waste of time , So today I will learn this code , There is no need to manually .
Here are some frames I captured from the video , I used an algorithm to delete these similar images , Get some different frames .
This is before the result :
This is the result of deleting similar pictures import os import cv2 from skimage.measure import compare_ssim # import shutil def delete(filename1):# Delete unwanted pictures os.remove(filename1) if __name__ == '__main__': #delete(r"D:\PycharmProjects\pythonProject\feiji\video_frames\5e062f3bd4040e480536f8f4708f388b.mp4\frame.128000.png") dir_path=r"D:\PycharmProjects\pythonProject\feiji\video_frames\5e062f3bd4040e480536f8f4708f388b.mp4" image_path=[] image_files=os.listdir(dir_path) image_files.sort(key=lambda x:int(x.split('.')[1]))# For sorting files , You can change the code according to your file name print(image_files) for image_file in image_files: image_path.append(os.path.join(dir_path,image_file)) print(image_path) image_0 = cv2.imread(image_path[0]) image_0_simp=image_0[:,:,0] print(image_0_simp.sum()) for image in image_path[1:]: image_1=cv2.imread(image) image_1_simp=image_1[:,:,0] # cv2.imshow("111",image_1_simp) # cv2.waitKey(0) ssim = compare_ssim(image_0_simp, image_1_simp, multichannel=True) print(ssim) if ssim>0.85: delete(image) else: image_0 = cv2.imread(image) image_0_simp = image_0[:, :, 0]
This effect is still good , It can be changed through the threshold .