reab5555 commited on
Commit
ada6dd5
·
verified ·
1 Parent(s): 07b109b

Update visualization.py

Browse files
Files changed (1) hide show
  1. visualization.py +10 -8
visualization.py CHANGED
@@ -203,7 +203,15 @@ def plot_posture(df, posture_scores, color='blue', anomaly_threshold=3):
203
  plt.close()
204
  return fig
205
 
206
- def create_video_with_heatmap(video_path, mse_heatmap_embeddings, mse_heatmap_posture, output_path, desired_fps):
 
 
 
 
 
 
 
 
207
  cap = cv2.VideoCapture(video_path)
208
  original_fps = cap.get(cv2.CAP_PROP_FPS)
209
  width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
@@ -219,13 +227,7 @@ def create_video_with_heatmap(video_path, mse_heatmap_embeddings, mse_heatmap_po
219
  if not ret:
220
  break
221
 
222
- heatmap_embeddings_img = np.frombuffer(mse_heatmap_embeddings, dtype='uint8')
223
- heatmap_embeddings_img = heatmap_embeddings_img.reshape((mse_heatmap_embeddings.get_height(), mse_heatmap_embeddings.get_width(), 3))
224
-
225
- heatmap_posture_img = np.frombuffer(mse_heatmap_posture, dtype='uint8')
226
- heatmap_posture_img = heatmap_posture_img.reshape((mse_heatmap_posture.get_height(), mse_heatmap_posture.get_width(), 3))
227
-
228
- heatmap_combined_img = np.vstack((heatmap_embeddings_img, heatmap_posture_img))
229
 
230
  combined_frame = np.vstack((frame, heatmap_combined_img))
231
 
 
203
  plt.close()
204
  return fig
205
 
206
+ def fig_to_img(fig):
207
+ canvas = FigureCanvasAgg(fig)
208
+ canvas.draw()
209
+ img = np.frombuffer(canvas.tostring_rgb(), dtype='uint8')
210
+ img = img.reshape(canvas.get_width_height()[::-1] + (3,))
211
+ plt.close(fig)
212
+ return img
213
+
214
+ def create_video_with_heatmap(video_path, mse_heatmap_embeddings_img, mse_heatmap_posture_img, output_path, desired_fps):
215
  cap = cv2.VideoCapture(video_path)
216
  original_fps = cap.get(cv2.CAP_PROP_FPS)
217
  width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
 
227
  if not ret:
228
  break
229
 
230
+ heatmap_combined_img = np.vstack((mse_heatmap_embeddings_img, mse_heatmap_posture_img))
 
 
 
 
 
 
231
 
232
  combined_frame = np.vstack((frame, heatmap_combined_img))
233