Spaces:
Sleeping
Sleeping
roychao19477
commited on
Commit
·
5327709
1
Parent(s):
ffbc4cf
Update module
Browse files
app.py
CHANGED
@@ -61,7 +61,6 @@ import tempfile
|
|
61 |
from ultralytics import YOLO
|
62 |
from moviepy import ImageSequenceClip
|
63 |
from scipy.io import wavfile
|
64 |
-
from PIL import Image, ImageOps
|
65 |
|
66 |
# Load face detector
|
67 |
model = YOLO("yolov8n-face.pt").cuda() # assumes CUDA available
|
@@ -167,18 +166,16 @@ def extract_faces(video_file):
|
|
167 |
face_crop = frame[y1:y2, x1:x2]
|
168 |
if face_crop.size != 0:
|
169 |
#resized = cv2.resize(face_crop, (224, 224))
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
resized = cv2.resize(square_crop, (224, 224))
|
181 |
-
frames.append(resized)
|
182 |
break # only one face per frame
|
183 |
|
184 |
cap.release()
|
|
|
61 |
from ultralytics import YOLO
|
62 |
from moviepy import ImageSequenceClip
|
63 |
from scipy.io import wavfile
|
|
|
64 |
|
65 |
# Load face detector
|
66 |
model = YOLO("yolov8n-face.pt").cuda() # assumes CUDA available
|
|
|
166 |
face_crop = frame[y1:y2, x1:x2]
|
167 |
if face_crop.size != 0:
|
168 |
#resized = cv2.resize(face_crop, (224, 224))
|
169 |
+
#frames.append(resized)
|
170 |
+
# Center crop 224x224 without resize
|
171 |
+
cy, cx = (y2 - y1) // 2, (x2 - x1) // 2
|
172 |
+
half = 112
|
173 |
+
start_y = max(0, cy - half)
|
174 |
+
start_x = max(0, cx - half)
|
175 |
+
center_crop = face_crop[start_y:start_y + 224, start_x:start_x + 224]
|
176 |
+
|
177 |
+
if center_crop.shape[0] == 224 and center_crop.shape[1] == 224:
|
178 |
+
frames.append(center_crop)
|
|
|
|
|
179 |
break # only one face per frame
|
180 |
|
181 |
cap.release()
|