Advertisement
Poganu

Image_Similarity

Apr 23rd, 2022
1,187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.85 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/Desktop/Python-Scripts/Server-Scripts/Image-Comparison/Similar-Frames'
  10.  
  11. # Numara cate fisiere sunt in folder
  12. path, dirs, files = next(
  13.     os.walk(folder_frames))
  14. file_count = len(files)
  15. print("Sunt ", file_count, " frame-uri")
  16.  
  17. print("-------------------")
  18.  
  19. file_list = os.listdir(folder_frames)
  20. # Face un array cu denuminile fisierelor .jpeg
  21. lista_frameuri = list(Tcl().call('lsort', '-dict', file_list))
  22.  
  23. #dir = sorted(os.listdir(os.getcwd()), key=len)
  24. #print(lista_frameuri)
  25.  
  26. start = time.perf_counter()
  27.  
  28. for x in range(100):#len(lista_frameuri)-1):
  29.    
  30.     # ----------HASH comparison------------------------------------------
  31.     frameX1 = os.path.join(folder_frames, lista_frameuri[x])
  32.     frameX2 = os.path.join(folder_frames, lista_frameuri[x+1])
  33.     # ----------Pregatirea imaginilor pentru MSE si SSIM----------------
  34.     # load the images -- the original, the original + contrast,
  35.     # and the original + photoshop
  36.     frameX1CV = cv2.imread(frameX1)
  37.     frameX2CV = cv2.imread(frameX2)
  38.     # convert the images to grayscale
  39.     image1 = cv2.cvtColor(frameX1CV, cv2.COLOR_BGR2GRAY)
  40.     image2 = cv2.cvtColor(frameX2CV, cv2.COLOR_BGR2GRAY)
  41.     # ----------MSE - Mean Squared Error - comparison-------------------
  42.     MSEerr_result = np.sum((image1.astype("float") - image2.astype("float")) ** 2)
  43.     MSEerr_result /= float(image1.shape[0] * image1.shape[1])
  44.     # ----------Afisarea rezultatelor----------------------------------
  45.     print(x, " intre: ", frameX1[-42:-5], "si", frameX2[-42:-5] , ": ", int(MSEerr_result))
  46.     # Stergerea fisierelor asemanatoare
  47.     #if diff == 0 or diff == 1:
  48.     #    print("Removed ", frameX1)
  49.     #    os.remove(frameX1)
  50.  
  51. end = time.perf_counter()
  52. print(end - start)
  53.  
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement