Spaces:
Sleeping
Sleeping
roychao19477
commited on
Commit
·
ffbc4cf
1
Parent(s):
bc3a003
Update module
Browse files
app.py
CHANGED
@@ -61,6 +61,7 @@ import tempfile
|
|
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
|
@@ -165,7 +166,18 @@ def extract_faces(video_file):
|
|
165 |
y2 = int(min(max(0, y2 + shift_down), h))
|
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 |
break # only one face per frame
|
171 |
|
|
|
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
|
|
|
166 |
y2 = int(min(max(0, y2 + shift_down), h))
|
167 |
face_crop = frame[y1:y2, x1:x2]
|
168 |
if face_crop.size != 0:
|
169 |
+
#resized = cv2.resize(face_crop, (224, 224))
|
170 |
+
def pad_to_square(img):
|
171 |
+
h, w = img.shape[:2]
|
172 |
+
size = max(h, w)
|
173 |
+
pad_top = (size - h) // 2
|
174 |
+
pad_bottom = size - h - pad_top
|
175 |
+
pad_left = (size - w) // 2
|
176 |
+
pad_right = size - w - pad_left
|
177 |
+
return cv2.copyMakeBorder(img, pad_top, pad_bottom, pad_left, pad_right, borderType=cv2.BORDER_CONSTANT, value=0)
|
178 |
+
|
179 |
+
square_crop = pad_to_square(face_crop)
|
180 |
+
resized = cv2.resize(square_crop, (224, 224))
|
181 |
frames.append(resized)
|
182 |
break # only one face per frame
|
183 |
|