Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,53 +1,47 @@
|
|
| 1 |
import os
|
| 2 |
-
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
#
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
return
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
#
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
similarity = torch.cosine_similarity(torch.tensor(embedding1), torch.tensor(embedding2))
|
| 49 |
-
if similarity < threshold:
|
| 50 |
-
non_matches.append((embedding1, embedding2))
|
| 51 |
-
|
| 52 |
-
for non_match in non_matches:
|
| 53 |
-
print(f"No match found: {non_match[0]} (Folder 1) and {non_match[1]} (Folder 2)")
|
|
|
|
| 1 |
import os
|
| 2 |
+
import cv2
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
def compare_images(image1, image2):
|
| 6 |
+
# Read the images
|
| 7 |
+
img1 = cv2.imread(r"C:\Users\nikit\OneDrive\Desktop\Test1")
|
| 8 |
+
img2 = cv2.imread(r"C:\Users\nikit\OneDrive\Desktop\Test2")
|
| 9 |
+
|
| 10 |
+
# Check if both images are loaded properly
|
| 11 |
+
if img1 is None or img2 is None:
|
| 12 |
+
return False
|
| 13 |
+
|
| 14 |
+
# Resize images to the same size
|
| 15 |
+
img1 = cv2.resize(img1, (100, 100))
|
| 16 |
+
img2 = cv2.resize(img2, (100, 100))
|
| 17 |
+
|
| 18 |
+
# Convert images to grayscale
|
| 19 |
+
gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
|
| 20 |
+
gray2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
|
| 21 |
+
|
| 22 |
+
# Calculate the Structural Similarity Index (SSI)
|
| 23 |
+
score, _ = cv2.compare_ssim(gray1, gray2, full=True)
|
| 24 |
+
|
| 25 |
+
# You can adjust the threshold based on your needs
|
| 26 |
+
return score >= 0.9 # Threshold for similarity
|
| 27 |
+
|
| 28 |
+
def compare_folders(staff_folder, unknown_folder):
|
| 29 |
+
for staff_image in os.listdir(staff_folder):
|
| 30 |
+
staff_image_path = os.path.join(staff_folder, staff_image)
|
| 31 |
+
found_match = False
|
| 32 |
+
|
| 33 |
+
for unknown_image in os.listdir(unknown_folder):
|
| 34 |
+
unknown_image_path = os.path.join(unknown_folder, unknown_image)
|
| 35 |
+
|
| 36 |
+
if compare_images(staff_image_path, unknown_image_path):
|
| 37 |
+
print(f"Match found: {staff_image} matches {unknown_image} (Staff)")
|
| 38 |
+
found_match = True
|
| 39 |
+
break
|
| 40 |
+
|
| 41 |
+
if not found_match:
|
| 42 |
+
print(f"No match found for {staff_image} (Unknown)")
|
| 43 |
+
|
| 44 |
+
# Usage
|
| 45 |
+
staff_folder_path = 'path/to/staff/images'
|
| 46 |
+
unknown_folder_path = 'path/to/unknown/images'
|
| 47 |
+
compare_folders(staff_folder_path, unknown_folder_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|