Spaces:
Runtime error
Runtime error
Update visualization.py
Browse files- visualization.py +9 -13
visualization.py
CHANGED
|
@@ -210,7 +210,7 @@ def plot_posture(df, posture_scores, color='blue', anomaly_threshold=3):
|
|
| 210 |
|
| 211 |
def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, mse_voice, output_path, desired_fps, largest_cluster):
|
| 212 |
# Filter the DataFrame to only include frames from the largest cluster
|
| 213 |
-
|
| 214 |
|
| 215 |
# Interpolate mse_voice to match the length of df
|
| 216 |
x_voice = np.linspace(0, len(mse_voice)-1, len(mse_voice))
|
|
@@ -220,12 +220,8 @@ def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, mse_v
|
|
| 220 |
|
| 221 |
mse_embeddings = mse_embeddings[df['Cluster'] == largest_cluster]
|
| 222 |
mse_posture = mse_posture[df['Cluster'] == largest_cluster]
|
| 223 |
-
|
| 224 |
|
| 225 |
-
mse_embeddings = mse_embeddings[df['Cluster'] == largest_cluster]
|
| 226 |
-
mse_posture = mse_posture[df['Cluster'] == largest_cluster]
|
| 227 |
-
mse_voice = mse_voice[df['Cluster'] == largest_cluster]
|
| 228 |
-
|
| 229 |
cap = cv2.VideoCapture(video_path)
|
| 230 |
original_fps = cap.get(cv2.CAP_PROP_FPS)
|
| 231 |
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
|
@@ -235,21 +231,21 @@ def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, mse_v
|
|
| 235 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 236 |
out = cv2.VideoWriter(output_path, fourcc, original_fps, (width, height + 200))
|
| 237 |
|
|
|
|
| 238 |
mse_embeddings = np.interp(np.linspace(0, len(mse_embeddings) - 1, total_frames),
|
| 239 |
np.arange(len(mse_embeddings)), mse_embeddings)
|
| 240 |
mse_posture = np.interp(np.linspace(0, len(mse_posture) - 1, total_frames),
|
| 241 |
np.arange(len(mse_posture)), mse_posture)
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
|
| 246 |
mse_embeddings_norm = (mse_embeddings - np.min(mse_embeddings)) / (np.max(mse_embeddings) - np.min(mse_embeddings))
|
| 247 |
mse_posture_norm = (mse_posture - np.min(mse_posture)) / (np.max(mse_posture) - np.min(mse_posture))
|
| 248 |
-
mse_voice_norm = (
|
| 249 |
|
| 250 |
-
combined_mse = np.zeros((
|
| 251 |
-
combined_mse[0] = mse_embeddings_norm
|
| 252 |
-
combined_mse[1] = mse_posture_norm
|
| 253 |
combined_mse[2] = mse_voice_norm
|
| 254 |
|
| 255 |
# Custom colormap definition
|
|
|
|
| 210 |
|
| 211 |
def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, mse_voice, output_path, desired_fps, largest_cluster):
|
| 212 |
# Filter the DataFrame to only include frames from the largest cluster
|
| 213 |
+
df_largest_cluster = df[df['Cluster'] == largest_cluster]
|
| 214 |
|
| 215 |
# Interpolate mse_voice to match the length of df
|
| 216 |
x_voice = np.linspace(0, len(mse_voice)-1, len(mse_voice))
|
|
|
|
| 220 |
|
| 221 |
mse_embeddings = mse_embeddings[df['Cluster'] == largest_cluster]
|
| 222 |
mse_posture = mse_posture[df['Cluster'] == largest_cluster]
|
| 223 |
+
mse_voice_interpolated = mse_voice_interpolated[df['Cluster'] == largest_cluster]
|
| 224 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
cap = cv2.VideoCapture(video_path)
|
| 226 |
original_fps = cap.get(cv2.CAP_PROP_FPS)
|
| 227 |
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
|
|
|
| 231 |
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
| 232 |
out = cv2.VideoWriter(output_path, fourcc, original_fps, (width, height + 200))
|
| 233 |
|
| 234 |
+
# Ensure all MSE arrays have the same length as total_frames
|
| 235 |
mse_embeddings = np.interp(np.linspace(0, len(mse_embeddings) - 1, total_frames),
|
| 236 |
np.arange(len(mse_embeddings)), mse_embeddings)
|
| 237 |
mse_posture = np.interp(np.linspace(0, len(mse_posture) - 1, total_frames),
|
| 238 |
np.arange(len(mse_posture)), mse_posture)
|
| 239 |
+
mse_voice_interpolated = np.interp(np.linspace(0, len(mse_voice_interpolated) - 1, total_frames),
|
| 240 |
+
np.arange(len(mse_voice_interpolated)), mse_voice_interpolated)
|
|
|
|
| 241 |
|
| 242 |
mse_embeddings_norm = (mse_embeddings - np.min(mse_embeddings)) / (np.max(mse_embeddings) - np.min(mse_embeddings))
|
| 243 |
mse_posture_norm = (mse_posture - np.min(mse_posture)) / (np.max(mse_posture) - np.min(mse_posture))
|
| 244 |
+
mse_voice_norm = (mse_voice_interpolated - np.min(mse_voice_interpolated)) / (np.max(mse_voice_interpolated) - np.min(mse_voice_interpolated))
|
| 245 |
|
| 246 |
+
combined_mse = np.zeros((3, total_frames))
|
| 247 |
+
combined_mse[0] = mse_embeddings_norm
|
| 248 |
+
combined_mse[1] = mse_posture_norm
|
| 249 |
combined_mse[2] = mse_voice_norm
|
| 250 |
|
| 251 |
# Custom colormap definition
|