程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python delete similar pictures in folder

編輯:Python

        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 . 


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved