Advertisement
Poganu

Filter-Similar-Files.py

Apr 24th, 2022
849
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.16 KB | None | 0 0
  1.  
  2. from tkinter import Tcl #OK
  3. import os #OK
  4. import numpy as np #OK
  5. import cv2 #OK
  6. import time
  7.  
  8. # Locatia standard pentru toate frame-urile
  9. folder_frames = '/Users/cristianpogan/Downloads/Test-comparatie-frames/outputlit2/Test-Data-24-Apr/No-Bin-24-Apr/'
  10. extension = ".jpeg"
  11.  
  12. # Numara cate fisiere sunt in folder
  13. path, dirs, files = next(
  14.     os.walk(folder_frames))
  15. file_count = len(files)
  16. print("Sunt ", file_count, " frame-uri")
  17.  
  18. print("-------------------")
  19.  
  20. file_list = os.listdir(folder_frames)
  21. # Face un array cu denuminile fisierelor .jpeg
  22. lista_frameuri = list(Tcl().call('lsort', '-dict', file_list))
  23.  
  24. #dir = sorted(os.listdir(os.getcwd()), key=len)
  25. #print(lista_frameuri)
  26.  
  27. start = time.perf_counter()
  28. over_threshold = 0
  29.  
  30.  
  31. for x in range(len(lista_frameuri)-1):
  32.    
  33.     print(lista_frameuri[x])
  34.     if lista_frameuri[x].endswith(extension):
  35.         # ----------HASH comparison------------------------------------------
  36.         frameX1 = os.path.join(folder_frames, lista_frameuri[x])
  37.         frameX2 = os.path.join(folder_frames, lista_frameuri[x+1])
  38.         # ----------Pregatirea imaginilor pentru MSE si SSIM----------------
  39.         # load the images -- the original, the original + contrast,
  40.         # and the original + photoshop
  41.         frameX1CV = cv2.imread(frameX1)
  42.         frameX2CV = cv2.imread(frameX2)
  43.         # convert the images to grayscale
  44.         image1 = cv2.cvtColor(frameX1CV, cv2.COLOR_BGR2GRAY)
  45.         image2 = cv2.cvtColor(frameX2CV, cv2.COLOR_BGR2GRAY)
  46.         # ----------MSE - Mean Squared Error - comparison-------------------
  47.         MSEerr_result = np.sum((image1.astype("float") - image2.astype("float")) ** 2)
  48.         MSEerr_result /= float(image1.shape[0] * image1.shape[1])
  49.         # ----------Afisarea rezultatelor----------------------------------
  50.         print(x, " intre: ", frameX1[-42:-5], "si", frameX2[-42:-5] , ": ", int(MSEerr_result))
  51.  
  52.         if MSEerr_result < 30:
  53.             over_threshold = over_threshold + 1
  54.             print("Removed ", frameX1)
  55.             os.remove(frameX1)
  56.         # Stergerea fisierelor asemanatoare
  57.         #if diff == 0 or diff == 1:
  58.         #    print("Removed ", frameX1)
  59.         #    os.remove(frameX1)
  60.     else:
  61.         pass
  62.  
  63. print("over_threshold: ", over_threshold)
  64. end = time.perf_counter()
  65. print(end - start)
  66.  
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement