Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,19 +5,33 @@ import mediapipe as mp
|
|
5 |
import matplotlib.pyplot as plt
|
6 |
from PIL import Image
|
7 |
import numpy as np
|
|
|
8 |
|
9 |
# Initialize MediaPipe Pose for body bounding box detection
|
10 |
mp_pose = mp.solutions.pose
|
11 |
|
12 |
def analyze_images(img1, img2):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
# Face comparison with DeepFace
|
14 |
-
face_result = DeepFace.verify(
|
15 |
is_same_person = face_result['verified']
|
16 |
similarity_score = face_result['distance']
|
17 |
|
18 |
# Convert images to OpenCV format
|
19 |
-
img1_cv = cv2.cvtColor(
|
20 |
-
img2_cv = cv2.cvtColor(
|
21 |
|
22 |
# Body analysis with MediaPipe
|
23 |
def get_body_info(image):
|
|
|
5 |
import matplotlib.pyplot as plt
|
6 |
from PIL import Image
|
7 |
import numpy as np
|
8 |
+
import tempfile
|
9 |
|
10 |
# Initialize MediaPipe Pose for body bounding box detection
|
11 |
mp_pose = mp.solutions.pose
|
12 |
|
13 |
def analyze_images(img1, img2):
|
14 |
+
# Option 1: Convert PIL images to NumPy arrays
|
15 |
+
img1_array = np.array(img1)
|
16 |
+
img2_array = np.array(img2)
|
17 |
+
|
18 |
+
# Option 2: Save images temporarily as JPEG files
|
19 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file1:
|
20 |
+
img1.save(temp_file1, format='JPEG')
|
21 |
+
img1_path = temp_file1.name
|
22 |
+
|
23 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".jpg") as temp_file2:
|
24 |
+
img2.save(temp_file2, format='JPEG')
|
25 |
+
img2_path = temp_file2.name
|
26 |
+
|
27 |
# Face comparison with DeepFace
|
28 |
+
face_result = DeepFace.verify(img1_path, img2_path, model_name='VGG-Face')
|
29 |
is_same_person = face_result['verified']
|
30 |
similarity_score = face_result['distance']
|
31 |
|
32 |
# Convert images to OpenCV format
|
33 |
+
img1_cv = cv2.cvtColor(img1_array, cv2.COLOR_RGB2BGR)
|
34 |
+
img2_cv = cv2.cvtColor(img2_array, cv2.COLOR_RGB2BGR)
|
35 |
|
36 |
# Body analysis with MediaPipe
|
37 |
def get_body_info(image):
|