Spaces:
Sleeping
Sleeping
roychao19477
commited on
Commit
·
6ab878e
1
Parent(s):
edb3fb0
Update module
Browse files
app.py
CHANGED
@@ -150,7 +150,7 @@ def extract_faces(video_file):
|
|
150 |
# version 2
|
151 |
h, w, _ = frame.shape
|
152 |
x1, y1, x2, y2 = box.xyxy[0].cpu().numpy()
|
153 |
-
pad_ratio = 0.
|
154 |
|
155 |
dx = (x2 - x1) * pad_ratio
|
156 |
dy = (y2 - y1) * pad_ratio
|
@@ -167,19 +167,15 @@ def extract_faces(video_file):
|
|
167 |
if face_crop.size != 0:
|
168 |
#resized = cv2.resize(face_crop, (224, 224))
|
169 |
#frames.append(resized)
|
|
|
170 |
h_crop, w_crop = face_crop.shape[:2]
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
# Make sure we don't go out of bounds
|
180 |
-
if end_y <= h_crop and end_x <= w_crop:
|
181 |
-
center_crop = face_crop[start_y:end_y, start_x:end_x]
|
182 |
-
frames.append(center_crop)
|
183 |
break # only one face per frame
|
184 |
|
185 |
cap.release()
|
|
|
150 |
# version 2
|
151 |
h, w, _ = frame.shape
|
152 |
x1, y1, x2, y2 = box.xyxy[0].cpu().numpy()
|
153 |
+
pad_ratio = 0.3 # 30% padding
|
154 |
|
155 |
dx = (x2 - x1) * pad_ratio
|
156 |
dy = (y2 - y1) * pad_ratio
|
|
|
167 |
if face_crop.size != 0:
|
168 |
#resized = cv2.resize(face_crop, (224, 224))
|
169 |
#frames.append(resized)
|
170 |
+
|
171 |
h_crop, w_crop = face_crop.shape[:2]
|
172 |
+
side = min(h_crop, w_crop)
|
173 |
+
start_y = (h_crop - side) // 2
|
174 |
+
start_x = (w_crop - side) // 2
|
175 |
+
square_crop = face_crop[start_y:start_y+side, start_x:start_x+side]
|
176 |
+
resized = cv2.resize(square_crop, (224, 224))
|
177 |
+
frames.append(resized)
|
178 |
+
|
|
|
|
|
|
|
|
|
|
|
179 |
break # only one face per frame
|
180 |
|
181 |
cap.release()
|