reab5555 commited on
Commit
0c437f5
·
verified ·
1 Parent(s): 724e632

Update video_processing.py

Browse files
Files changed (1) hide show
  1. video_processing.py +12 -30
video_processing.py CHANGED
@@ -155,18 +155,17 @@ def process_video(video_path, anomaly_threshold, desired_fps, progress=None):
155
  try:
156
  X_posture = np.array([posture_scores_by_frame.get(frame, None) for frame in df['Frame']])
157
  X_posture = X_posture[X_posture != None].reshape(-1, 1)
158
-
159
  if len(X_posture) == 0:
160
  raise ValueError("No valid posture data found")
161
-
162
  mse_embeddings, mse_posture = anomaly_detection(X_embeddings, X_posture)
163
-
164
  # Extract audio from video
165
  video = AudioSegment.from_file(video_path, "mp4")
166
  audio_path = os.path.join(temp_dir, "audio.wav")
167
  video.export(audio_path, format="wav")
168
-
169
- try:
170
  # Process audio
171
  most_frequent_voice, voice_features, voice_clusters = process_audio(audio_path)
172
 
@@ -178,41 +177,24 @@ def process_video(video_path, anomaly_threshold, desired_fps, progress=None):
178
  X_voice = np.array(most_frequent_voice)
179
  mse_voice = anomaly_detection(X_voice, X_voice)
180
 
181
- # Generate plots for voice
182
- mse_plot_voice, anomaly_segments_voice = plot_mse(df, mse_voice, "Voice",
183
- color='green',
184
- anomaly_threshold=anomaly_threshold)
185
- mse_histogram_voice = plot_mse_histogram(mse_voice, "MSE Distribution: Voice",
186
- anomaly_threshold, color='green')
187
- mse_heatmap_voice = plot_mse_heatmap(mse_voice, "Voice MSE Heatmap", df)
188
- except Exception as e:
189
- print(f"Error in voice processing: {str(e)}")
190
- mse_voice = None
191
- mse_plot_voice = None
192
- mse_histogram_voice = None
193
- mse_heatmap_voice = None
194
- anomaly_segments_voice = None
195
-
196
-
197
  progress(0.95, "Generating plots")
 
 
198
  mse_plot_embeddings, anomaly_frames_embeddings = plot_mse(df, mse_embeddings, "Facial Features",
199
  color=GRAPH_COLORS['facial_embeddings'],
200
  anomaly_threshold=anomaly_threshold)
201
-
202
  mse_histogram_embeddings = plot_mse_histogram(mse_embeddings, "MSE Distribution: Facial Features",
203
  anomaly_threshold, color=GRAPH_COLORS['facial_embeddings'])
204
-
 
 
205
  mse_plot_posture, anomaly_frames_posture = plot_mse(df, mse_posture, "Body Posture",
206
  color=GRAPH_COLORS['body_posture'],
207
  anomaly_threshold=anomaly_threshold)
208
-
209
  mse_histogram_posture = plot_mse_histogram(mse_posture, "MSE Distribution: Body Posture",
210
  anomaly_threshold, color=GRAPH_COLORS['body_posture'])
211
-
212
  mse_heatmap_posture = plot_mse_heatmap(mse_posture, "Body Posture MSE Heatmap", df)
213
-
214
- mse_heatmap_embeddings = plot_mse_heatmap(mse_embeddings, "Facial Features MSE Heatmap", df)
215
-
216
  # Generate plots for voice
217
  mse_plot_voice, anomaly_segments_voice = plot_mse(df, mse_voice, "Voice",
218
  color='green',
@@ -220,12 +202,12 @@ def process_video(video_path, anomaly_threshold, desired_fps, progress=None):
220
  mse_histogram_voice = plot_mse_histogram(mse_voice, "MSE Distribution: Voice",
221
  anomaly_threshold, color='green')
222
  mse_heatmap_voice = plot_mse_heatmap(mse_voice, "Voice MSE Heatmap", df)
223
-
224
  except Exception as e:
225
  print(f"Error details: {str(e)}")
226
  import traceback
227
  traceback.print_exc()
228
- return (f"Error in video processing: {str(e)}",) + (None,) * 14
229
 
230
  progress(1.0, "Preparing results")
231
  results = f"Number of persons detected: {num_clusters}\n\n"
 
155
  try:
156
  X_posture = np.array([posture_scores_by_frame.get(frame, None) for frame in df['Frame']])
157
  X_posture = X_posture[X_posture != None].reshape(-1, 1)
158
+
159
  if len(X_posture) == 0:
160
  raise ValueError("No valid posture data found")
161
+
162
  mse_embeddings, mse_posture = anomaly_detection(X_embeddings, X_posture)
163
+
164
  # Extract audio from video
165
  video = AudioSegment.from_file(video_path, "mp4")
166
  audio_path = os.path.join(temp_dir, "audio.wav")
167
  video.export(audio_path, format="wav")
168
+
 
169
  # Process audio
170
  most_frequent_voice, voice_features, voice_clusters = process_audio(audio_path)
171
 
 
177
  X_voice = np.array(most_frequent_voice)
178
  mse_voice = anomaly_detection(X_voice, X_voice)
179
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  progress(0.95, "Generating plots")
181
+
182
+ # Generate plots for facial features
183
  mse_plot_embeddings, anomaly_frames_embeddings = plot_mse(df, mse_embeddings, "Facial Features",
184
  color=GRAPH_COLORS['facial_embeddings'],
185
  anomaly_threshold=anomaly_threshold)
 
186
  mse_histogram_embeddings = plot_mse_histogram(mse_embeddings, "MSE Distribution: Facial Features",
187
  anomaly_threshold, color=GRAPH_COLORS['facial_embeddings'])
188
+ mse_heatmap_embeddings = plot_mse_heatmap(mse_embeddings, "Facial Features MSE Heatmap", df)
189
+
190
+ # Generate plots for body posture
191
  mse_plot_posture, anomaly_frames_posture = plot_mse(df, mse_posture, "Body Posture",
192
  color=GRAPH_COLORS['body_posture'],
193
  anomaly_threshold=anomaly_threshold)
 
194
  mse_histogram_posture = plot_mse_histogram(mse_posture, "MSE Distribution: Body Posture",
195
  anomaly_threshold, color=GRAPH_COLORS['body_posture'])
 
196
  mse_heatmap_posture = plot_mse_heatmap(mse_posture, "Body Posture MSE Heatmap", df)
197
+
 
 
198
  # Generate plots for voice
199
  mse_plot_voice, anomaly_segments_voice = plot_mse(df, mse_voice, "Voice",
200
  color='green',
 
202
  mse_histogram_voice = plot_mse_histogram(mse_voice, "MSE Distribution: Voice",
203
  anomaly_threshold, color='green')
204
  mse_heatmap_voice = plot_mse_heatmap(mse_voice, "Voice MSE Heatmap", df)
205
+
206
  except Exception as e:
207
  print(f"Error details: {str(e)}")
208
  import traceback
209
  traceback.print_exc()
210
+ return (f"Error in video processing: {str(e)}",) + (None,) * 20
211
 
212
  progress(1.0, "Preparing results")
213
  results = f"Number of persons detected: {num_clusters}\n\n"