reab5555 commited on
Commit
76acc83
·
verified ·
1 Parent(s): 5a5fe49

Update video_processing.py

Browse files
Files changed (1) hide show
  1. video_processing.py +1 -6
video_processing.py CHANGED
@@ -22,7 +22,6 @@ mtcnn = MTCNN(keep_all=False, device=device, thresholds=[0.9, 0.9, 0.9], min_fac
22
  mp_face_mesh = mp.solutions.face_mesh
23
  face_mesh = mp_face_mesh.FaceMesh(static_image_mode=False, max_num_faces=1, min_detection_confidence=0.8)
24
 
25
-
26
  def extract_frames(video_path, output_folder, desired_fps, progress_callback=None):
27
  os.makedirs(output_folder, exist_ok=True)
28
  clip = VideoFileClip(video_path)
@@ -45,7 +44,6 @@ def extract_frames(video_path, output_folder, desired_fps, progress_callback=Non
45
  clip.close()
46
  return frame_count, original_fps
47
 
48
-
49
  def process_frames(frames_folder, aligned_faces_folder, frame_count, progress):
50
  embeddings_by_frame = {}
51
  posture_scores_by_frame = {}
@@ -89,7 +87,6 @@ def process_frames(frames_folder, aligned_faces_folder, frame_count, progress):
89
 
90
  return embeddings_by_frame, posture_scores_by_frame, posture_landmarks_by_frame, aligned_face_paths, facial_landmarks_by_frame
91
 
92
-
93
  def process_video(video_path, anomaly_threshold, desired_fps, progress=None):
94
  start_time = time.time()
95
  output_folder = "output"
@@ -182,6 +179,7 @@ def process_video(video_path, anomaly_threshold, desired_fps, progress=None):
182
  progress(0.9, "Generating video with heatmap")
183
 
184
  # Create video with heatmap
 
185
  heatmap_video_path = create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, heatmap_video_path, desired_fps, largest_cluster)
186
 
187
  except Exception as e:
@@ -254,7 +252,6 @@ def process_video(video_path, anomaly_threshold, desired_fps, progress=None):
254
  heatmap_video_path
255
  )
256
 
257
-
258
  def is_frontal_face(landmarks, threshold=60):
259
  nose_tip = landmarks[4]
260
  left_chin = landmarks[234]
@@ -269,7 +266,6 @@ def is_frontal_face(landmarks, threshold=60):
269
  angle_degrees = math.degrees(angle)
270
  return abs(180 - angle_degrees) < threshold
271
 
272
-
273
  def save_person_data_to_csv(embeddings_by_frame, clusters, desired_fps, original_fps, output_folder, video_duration):
274
  person_data = {}
275
 
@@ -303,7 +299,6 @@ def save_person_data_to_csv(embeddings_by_frame, clusters, desired_fps, original
303
 
304
  return df, largest_cluster
305
 
306
-
307
  def get_all_face_samples(organized_faces_folder, output_folder, largest_cluster, max_samples=100):
308
  face_samples = {"most_frequent": [], "others": []}
309
  for cluster_folder in sorted(os.listdir(organized_faces_folder)):
 
22
  mp_face_mesh = mp.solutions.face_mesh
23
  face_mesh = mp_face_mesh.FaceMesh(static_image_mode=False, max_num_faces=1, min_detection_confidence=0.8)
24
 
 
25
  def extract_frames(video_path, output_folder, desired_fps, progress_callback=None):
26
  os.makedirs(output_folder, exist_ok=True)
27
  clip = VideoFileClip(video_path)
 
44
  clip.close()
45
  return frame_count, original_fps
46
 
 
47
  def process_frames(frames_folder, aligned_faces_folder, frame_count, progress):
48
  embeddings_by_frame = {}
49
  posture_scores_by_frame = {}
 
87
 
88
  return embeddings_by_frame, posture_scores_by_frame, posture_landmarks_by_frame, aligned_face_paths, facial_landmarks_by_frame
89
 
 
90
  def process_video(video_path, anomaly_threshold, desired_fps, progress=None):
91
  start_time = time.time()
92
  output_folder = "output"
 
179
  progress(0.9, "Generating video with heatmap")
180
 
181
  # Create video with heatmap
182
+ heatmap_video_path = os.path.join(output_folder, "heatmap_video.mp4")
183
  heatmap_video_path = create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, heatmap_video_path, desired_fps, largest_cluster)
184
 
185
  except Exception as e:
 
252
  heatmap_video_path
253
  )
254
 
 
255
  def is_frontal_face(landmarks, threshold=60):
256
  nose_tip = landmarks[4]
257
  left_chin = landmarks[234]
 
266
  angle_degrees = math.degrees(angle)
267
  return abs(180 - angle_degrees) < threshold
268
 
 
269
  def save_person_data_to_csv(embeddings_by_frame, clusters, desired_fps, original_fps, output_folder, video_duration):
270
  person_data = {}
271
 
 
299
 
300
  return df, largest_cluster
301
 
 
302
  def get_all_face_samples(organized_faces_folder, output_folder, largest_cluster, max_samples=100):
303
  face_samples = {"most_frequent": [], "others": []}
304
  for cluster_folder in sorted(os.listdir(organized_faces_folder)):