roychao19477 commited on
Commit
6ab878e
·
1 Parent(s): edb3fb0

Update module

Browse files
Files changed (1) hide show
  1. app.py +9 -13
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.5 # 30% padding
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
- 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()
 
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()