Ajay98 commited on
Commit
9146a93
·
verified ·
1 Parent(s): 40ad35a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -9
app.py CHANGED
@@ -2,17 +2,54 @@ import os
2
  import cv2
3
  import numpy as np
4
 
5
- staff_folder_path = r"C:\Users\nikit\OneDrive\Desktop\Test1" # Replace with the correct path
6
- unknown_folder_path = r"C:\Users\nikit\OneDrive\Desktop\Test2" # Replace with the correct path
 
7
 
8
- print(f"Staff folder path: {staff_folder_path}")
9
- print(f"Unknown folder path: {unknown_folder_path}")
10
- import os
11
 
12
- if os.path.exists(path):
13
- print("Path exists!")
14
- else:
15
- print("Path does not exist.")
 
 
 
16
 
 
 
 
 
 
 
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
 
 
 
2
  import cv2
3
  import numpy as np
4
 
5
+ def compare_images(image1, image2):
6
+ img1 = cv2.imread(image1)
7
+ img2 = cv2.imread(image2)
8
 
9
+ if img1 is None or img2 is None:
10
+ return False
 
11
 
12
+ img1 = cv2.resize(img1, (100, 100))
13
+ img2 = cv2.resize(img2, (100, 100))
14
+
15
+ gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
16
+ gray2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
17
+
18
+ score, _ = cv2.compare_ssim(gray1, gray2, full=True)
19
 
20
+ return score >= 0.9
21
+
22
+ def compare_folders(staff_folder, unknown_folder):
23
+ if not os.path.exists(staff_folder):
24
+ print(f"Error: Staff folder '{staff_folder}' does not exist.")
25
+ return
26
 
27
+ if not os.path.exists(unknown_folder):
28
+ print(f"Error: Unknown folder '{unknown_folder}' does not exist.")
29
+ return
30
+
31
+ for staff_image in os.listdir(staff_folder):
32
+ staff_image_path = os.path.join(staff_folder, staff_image)
33
+ found_match = False
34
+
35
+ for unknown_image in os.listdir(unknown_folder):
36
+ unknown_image_path = os.path.join(unknown_folder, unknown_image)
37
+
38
+ if compare_images(staff_image_path, unknown_image_path):
39
+ print(f"Match found: {staff_image} matches {unknown_image} (Staff)")
40
+ found_match = True
41
+ break
42
+
43
+ if not found_match:
44
+ print(f"No match found for {staff_image} (Unknown)")
45
+
46
+ # Define the paths
47
+ staff_folder_path = r"C:\Users\nikit\OneDrive\Desktop\Test1" # Update to your actual path
48
+ unknown_folder_path = r"C:\Users\nikit\OneDrive\Desktop\Test2" # Update to your actual path
49
+
50
+ # Print paths for debugging
51
+ print(f"Staff folder path: {staff_folder_path}")
52
+ print(f"Unknown folder path: {unknown_folder_path}")
53
 
54
+ # Compare folders
55
+ compare_folders(staff_folder_path, unknown_folder_path)