reab5555 commited on
Commit
4d670fa
·
verified ·
1 Parent(s): ebcd47c

Update visualization.py

Browse files
Files changed (1) hide show
  1. visualization.py +5 -8
visualization.py CHANGED
@@ -217,10 +217,10 @@ def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, outpu
217
  total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
218
 
219
  fourcc = cv2.VideoWriter_fourcc(*'mp4v')
220
- out = cv2.VideoWriter(output_path, fourcc, desired_fps, (width, height + 200))
221
 
222
  cmap = mcolors.LinearSegmentedColormap.from_list("custom",
223
- [(1, 1, 1), (0, 0, 1), (0.5, 0, 0.5)], N=256)
224
 
225
  mse_embeddings = np.interp(np.linspace(0, len(mse_embeddings) - 1, total_frames),
226
  np.arange(len(mse_embeddings)), mse_embeddings)
@@ -231,8 +231,8 @@ def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, outpu
231
  mse_posture_norm = (mse_posture - np.min(mse_posture)) / (np.max(mse_posture) - np.min(mse_posture))
232
 
233
  combined_mse = np.zeros((2, total_frames, 3))
234
- combined_mse[0] = np.array([1 - mse_embeddings_norm, 1 - mse_embeddings_norm, mse_embeddings_norm]).T
235
- combined_mse[1] = np.array([1 - mse_posture_norm, mse_posture_norm, 1 - mse_posture_norm]).T
236
 
237
  fig, ax = plt.subplots(figsize=(width/100, 2))
238
  im = ax.imshow(combined_mse, aspect='auto', extent=[0, total_frames, 0, 2])
@@ -242,9 +242,7 @@ def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, outpu
242
  plt.tight_layout()
243
 
244
  line = None
245
- frame_interval = int(original_fps / desired_fps)
246
-
247
- for frame_count in range(0, total_frames, frame_interval):
248
  cap.set(cv2.CAP_PROP_POS_FRAMES, frame_count)
249
  ret, frame = cap.read()
250
  if not ret:
@@ -273,4 +271,3 @@ def create_video_with_heatmap(video_path, df, mse_embeddings, mse_posture, outpu
273
  plt.close(fig)
274
 
275
  return output_path
276
-
 
217
  total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
218
 
219
  fourcc = cv2.VideoWriter_fourcc(*'mp4v')
220
+ out = cv2.VideoWriter(output_path, fourcc, original_fps, (width, height + 200))
221
 
222
  cmap = mcolors.LinearSegmentedColormap.from_list("custom",
223
+ [(1, 1, 1), (1, 0, 0)], N=256) # More reddish for higher MSE values
224
 
225
  mse_embeddings = np.interp(np.linspace(0, len(mse_embeddings) - 1, total_frames),
226
  np.arange(len(mse_embeddings)), mse_embeddings)
 
231
  mse_posture_norm = (mse_posture - np.min(mse_posture)) / (np.max(mse_posture) - np.min(mse_posture))
232
 
233
  combined_mse = np.zeros((2, total_frames, 3))
234
+ combined_mse[0] = np.array([1, 1 - mse_embeddings_norm, 1 - mse_embeddings_norm]).T # More reddish for facial
235
+ combined_mse[1] = np.array([1, 1 - mse_posture_norm, 1 - mse_posture_norm]).T # More reddish for posture
236
 
237
  fig, ax = plt.subplots(figsize=(width/100, 2))
238
  im = ax.imshow(combined_mse, aspect='auto', extent=[0, total_frames, 0, 2])
 
242
  plt.tight_layout()
243
 
244
  line = None
245
+ for frame_count in range(total_frames):
 
 
246
  cap.set(cv2.CAP_PROP_POS_FRAMES, frame_count)
247
  ret, frame = cap.read()
248
  if not ret:
 
271
  plt.close(fig)
272
 
273
  return output_path