Update app.py
Browse files
app.py
CHANGED
@@ -92,8 +92,8 @@ def extract_and_align_faces_from_video(video_path, aligned_faces_folder, desired
|
|
92 |
for frame_num in range(0, frame_count, int(original_fps / desired_fps)):
|
93 |
video.set(cv2.CAP_PROP_POS_FRAMES, frame_num)
|
94 |
ret, frame = video.read()
|
95 |
-
if not ret or frame is None:
|
96 |
-
print(f"
|
97 |
continue
|
98 |
try:
|
99 |
boxes, probs = mtcnn.detect(frame)
|
@@ -102,6 +102,9 @@ def extract_and_align_faces_from_video(video_path, aligned_faces_folder, desired
|
|
102 |
if probs[0] >= 0.99:
|
103 |
x1, y1, x2, y2 = [int(b) for b in box]
|
104 |
face = frame[y1:y2, x1:x2]
|
|
|
|
|
|
|
105 |
aligned_face = alignFace(face)
|
106 |
if aligned_face is not None:
|
107 |
aligned_face_resized = cv2.resize(aligned_face, (160, 160))
|
|
|
92 |
for frame_num in range(0, frame_count, int(original_fps / desired_fps)):
|
93 |
video.set(cv2.CAP_PROP_POS_FRAMES, frame_num)
|
94 |
ret, frame = video.read()
|
95 |
+
if not ret or frame is None or frame.size == 0:
|
96 |
+
print(f"Skipping frame {frame_num}: Frame is empty or couldn't be read")
|
97 |
continue
|
98 |
try:
|
99 |
boxes, probs = mtcnn.detect(frame)
|
|
|
102 |
if probs[0] >= 0.99:
|
103 |
x1, y1, x2, y2 = [int(b) for b in box]
|
104 |
face = frame[y1:y2, x1:x2]
|
105 |
+
if face.size == 0:
|
106 |
+
print(f"Skipping frame {frame_num}: Detected face region is empty")
|
107 |
+
continue
|
108 |
aligned_face = alignFace(face)
|
109 |
if aligned_face is not None:
|
110 |
aligned_face_resized = cv2.resize(aligned_face, (160, 160))
|