Update video_processing.py
Browse files- video_processing.py +8 -6
video_processing.py
CHANGED
@@ -133,20 +133,20 @@ def process_video(video_path, anomaly_threshold, desired_fps, progress=None):
|
|
133 |
clusters = cluster_faces(embeddings)
|
134 |
num_clusters = len(set(clusters))
|
135 |
|
136 |
-
progress(0.
|
137 |
organize_faces_by_person(embeddings_by_frame, clusters, aligned_faces_folder, organized_faces_folder)
|
138 |
|
139 |
-
progress(0.
|
140 |
df, largest_cluster = save_person_data_to_csv(embeddings_by_frame, clusters, desired_fps,
|
141 |
original_fps, temp_dir, video_duration)
|
142 |
|
143 |
df['Seconds'] = df['Timecode'].apply(
|
144 |
lambda x: sum(float(t) * 60 ** i for i, t in enumerate(reversed(x.split(':')))))
|
145 |
|
146 |
-
progress(0.
|
147 |
face_samples = get_all_face_samples(organized_faces_folder, output_folder, largest_cluster)
|
148 |
|
149 |
-
progress(0.
|
150 |
embedding_columns = [col for col in df.columns if col.startswith('Raw_Embedding_')]
|
151 |
|
152 |
X_embeddings = df[embedding_columns].values
|
@@ -160,7 +160,7 @@ def process_video(video_path, anomaly_threshold, desired_fps, progress=None):
|
|
160 |
|
161 |
mse_embeddings, mse_posture = anomaly_detection(X_embeddings, X_posture)
|
162 |
|
163 |
-
progress(0.
|
164 |
mse_plot_embeddings, anomaly_frames_embeddings = plot_mse(df, mse_embeddings, "Facial Features",
|
165 |
color=GRAPH_COLORS['facial_embeddings'],
|
166 |
anomaly_threshold=anomaly_threshold)
|
@@ -179,9 +179,11 @@ def process_video(video_path, anomaly_threshold, desired_fps, progress=None):
|
|
179 |
|
180 |
mse_heatmap_embeddings = plot_mse_heatmap(mse_embeddings, "Facial Features MSE Heatmap", df)
|
181 |
|
|
|
|
|
182 |
# Create video with heatmap
|
183 |
heatmap_video_path = os.path.join(output_folder, "video_with_heatmap.mp4")
|
184 |
-
create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture,
|
185 |
|
186 |
except Exception as e:
|
187 |
print(f"Error details: {str(e)}")
|
|
|
133 |
clusters = cluster_faces(embeddings)
|
134 |
num_clusters = len(set(clusters))
|
135 |
|
136 |
+
progress(0.65, "Organizing faces")
|
137 |
organize_faces_by_person(embeddings_by_frame, clusters, aligned_faces_folder, organized_faces_folder)
|
138 |
|
139 |
+
progress(0.7, "Saving person data")
|
140 |
df, largest_cluster = save_person_data_to_csv(embeddings_by_frame, clusters, desired_fps,
|
141 |
original_fps, temp_dir, video_duration)
|
142 |
|
143 |
df['Seconds'] = df['Timecode'].apply(
|
144 |
lambda x: sum(float(t) * 60 ** i for i, t in enumerate(reversed(x.split(':')))))
|
145 |
|
146 |
+
progress(0.75, "Getting face samples")
|
147 |
face_samples = get_all_face_samples(organized_faces_folder, output_folder, largest_cluster)
|
148 |
|
149 |
+
progress(0.8, "Performing anomaly detection")
|
150 |
embedding_columns = [col for col in df.columns if col.startswith('Raw_Embedding_')]
|
151 |
|
152 |
X_embeddings = df[embedding_columns].values
|
|
|
160 |
|
161 |
mse_embeddings, mse_posture = anomaly_detection(X_embeddings, X_posture)
|
162 |
|
163 |
+
progress(0.85, "Generating graphs")
|
164 |
mse_plot_embeddings, anomaly_frames_embeddings = plot_mse(df, mse_embeddings, "Facial Features",
|
165 |
color=GRAPH_COLORS['facial_embeddings'],
|
166 |
anomaly_threshold=anomaly_threshold)
|
|
|
179 |
|
180 |
mse_heatmap_embeddings = plot_mse_heatmap(mse_embeddings, "Facial Features MSE Heatmap", df)
|
181 |
|
182 |
+
progress(0.9, "Generating video with heatmap")
|
183 |
+
|
184 |
# Create video with heatmap
|
185 |
heatmap_video_path = os.path.join(output_folder, "video_with_heatmap.mp4")
|
186 |
+
create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, output_path, desired_fps)
|
187 |
|
188 |
except Exception as e:
|
189 |
print(f"Error details: {str(e)}")
|