reab5555 commited on
Commit
0010645
·
verified ·
1 Parent(s): d4e6f9d

Update video_processing.py

Browse files
Files changed (1) hide show
  1. video_processing.py +16 -14
video_processing.py CHANGED
@@ -65,31 +65,33 @@ def process_frames(frames_folder, aligned_faces_folder, frame_count, progress):
65
  posture_score, posture_landmarks = calculate_posture_score(frame)
66
  posture_scores_by_frame[frame_num] = posture_score
67
  posture_landmarks_by_frame[frame_num] = posture_landmarks
68
- if results.multi_face_landmarks:
69
- facial_landmarks_by_frame[frame_num] = results.multi_face_landmarks[0]
70
-
71
  boxes, probs = mtcnn.detect(frame)
72
 
73
  if boxes is not None and len(boxes) > 0 and probs[0] >= 0.99:
74
  x1, y1, x2, y2 = [int(b) for b in boxes[0]]
75
  face = frame[y1:y2, x1:x2]
76
  if face.size > 0:
77
- results = face_mesh.process(cv2.cvtColor(face, cv2.COLOR_BGR2RGB))
78
- if results.multi_face_landmarks and is_frontal_face(results.multi_face_landmarks[0].landmark):
79
- aligned_face = face
80
-
81
- if aligned_face is not None:
82
- aligned_face_resized = cv2.resize(aligned_face, (160, 160))
83
- output_path = os.path.join(aligned_faces_folder, f"frame_{frame_num}_face.jpg")
84
- cv2.imwrite(output_path, aligned_face_resized)
85
- aligned_face_paths.append(output_path)
86
- embedding = get_face_embedding(aligned_face_resized)
87
- embeddings_by_frame[frame_num] = embedding
 
 
 
88
 
89
  progress((i + 1) / len(frame_files), f"Processing frame {i + 1} of {len(frame_files)}")
90
 
91
  return embeddings_by_frame, posture_scores_by_frame, posture_landmarks_by_frame, aligned_face_paths, facial_landmarks_by_frame
92
 
 
93
  def process_video(video_path, anomaly_threshold, desired_fps, progress=None):
94
  start_time = time.time()
95
  output_folder = "output"
 
65
  posture_score, posture_landmarks = calculate_posture_score(frame)
66
  posture_scores_by_frame[frame_num] = posture_score
67
  posture_landmarks_by_frame[frame_num] = posture_landmarks
68
+
 
 
69
  boxes, probs = mtcnn.detect(frame)
70
 
71
  if boxes is not None and len(boxes) > 0 and probs[0] >= 0.99:
72
  x1, y1, x2, y2 = [int(b) for b in boxes[0]]
73
  face = frame[y1:y2, x1:x2]
74
  if face.size > 0:
75
+ face_rgb = cv2.cvtColor(face, cv2.COLOR_BGR2RGB)
76
+ results = face_mesh.process(face_rgb)
77
+ if results.multi_face_landmarks:
78
+ facial_landmarks_by_frame[frame_num] = results.multi_face_landmarks[0]
79
+ if is_frontal_face(results.multi_face_landmarks[0].landmark):
80
+ aligned_face = face
81
+
82
+ if aligned_face is not None:
83
+ aligned_face_resized = cv2.resize(aligned_face, (160, 160))
84
+ output_path = os.path.join(aligned_faces_folder, f"frame_{frame_num}_face.jpg")
85
+ cv2.imwrite(output_path, aligned_face_resized)
86
+ aligned_face_paths.append(output_path)
87
+ embedding = get_face_embedding(aligned_face_resized)
88
+ embeddings_by_frame[frame_num] = embedding
89
 
90
  progress((i + 1) / len(frame_files), f"Processing frame {i + 1} of {len(frame_files)}")
91
 
92
  return embeddings_by_frame, posture_scores_by_frame, posture_landmarks_by_frame, aligned_face_paths, facial_landmarks_by_frame
93
 
94
+
95
  def process_video(video_path, anomaly_threshold, desired_fps, progress=None):
96
  start_time = time.time()
97
  output_folder = "output"