roychao19477 commited on
Commit
5327709
·
1 Parent(s): ffbc4cf

Update module

Browse files
Files changed (1) hide show
  1. app.py +10 -13
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
- 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
 
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()