Spaces:
Sleeping
Sleeping
roychao19477
commited on
Commit
·
edb3fb0
1
Parent(s):
79fa1e3
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,12 +167,19 @@ def extract_faces(video_file):
|
|
167 |
if face_crop.size != 0:
|
168 |
#resized = cv2.resize(face_crop, (224, 224))
|
169 |
#frames.append(resized)
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
break # only one face per frame
|
177 |
|
178 |
cap.release()
|
|
|
150 |
# version 2
|
151 |
h, w, _ = frame.shape
|
152 |
x1, y1, x2, y2 = box.xyxy[0].cpu().numpy()
|
153 |
+
pad_ratio = 0.5 # 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 |
+
h_crop, w_crop = face_crop.shape[:2]
|
171 |
+
cy, cx = h_crop // 2, w_crop // 2
|
172 |
+
half = 112
|
173 |
+
|
174 |
+
start_y = max(0, cy - half)
|
175 |
+
end_y = start_y + 224
|
176 |
+
start_x = max(0, cx - half)
|
177 |
+
end_x = start_x + 224
|
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()
|