Update WorldCanvas_data/worldcanvas_data_pipeline/cotracker/cotracker/utils/visualizer.py
Browse files
WorldCanvas_data/worldcanvas_data_pipeline/cotracker/cotracker/utils/visualizer.py
CHANGED
|
@@ -28,24 +28,6 @@ def read_video_from_path(path):
|
|
| 28 |
return np.stack(frames)
|
| 29 |
|
| 30 |
|
| 31 |
-
# def draw_circle(rgb, coord, radius, color=(255, 0, 0), visible=True, color_alpha=None):
|
| 32 |
-
# # Create a draw object
|
| 33 |
-
# if not visible:
|
| 34 |
-
# return rgb
|
| 35 |
-
# draw = ImageDraw.Draw(rgb)
|
| 36 |
-
# # Calculate the bounding box of the circle
|
| 37 |
-
# left_up_point = (coord[0] - radius, coord[1] - radius)
|
| 38 |
-
# right_down_point = (coord[0] + radius, coord[1] + radius)
|
| 39 |
-
# # Draw the circle
|
| 40 |
-
# color = tuple(list(color) + [color_alpha if color_alpha is not None else 255])
|
| 41 |
-
|
| 42 |
-
# draw.ellipse(
|
| 43 |
-
# [left_up_point, right_down_point],
|
| 44 |
-
# fill=tuple(color) if visible else None,
|
| 45 |
-
# outline=tuple(color),
|
| 46 |
-
# )
|
| 47 |
-
# return rgb
|
| 48 |
-
|
| 49 |
def draw_circle(rgb, coord, radius, color=(255, 0, 0), visible=True, color_alpha=None):
|
| 50 |
# Create a draw object
|
| 51 |
if not visible:
|
|
@@ -93,10 +75,6 @@ class Visualizer:
|
|
| 93 |
):
|
| 94 |
self.mode = mode
|
| 95 |
self.save_dir = save_dir
|
| 96 |
-
# if mode == "rainbow":
|
| 97 |
-
# self.color_map = cm.get_cmap("gist_rainbow")
|
| 98 |
-
# elif mode == "cool":
|
| 99 |
-
# self.color_map = cm.get_cmap(mode)
|
| 100 |
self.show_first_frame = show_first_frame
|
| 101 |
self.grayscale = grayscale
|
| 102 |
self.tracks_leave_trace = tracks_leave_trace
|
|
@@ -177,7 +155,6 @@ class Visualizer:
|
|
| 177 |
video_writer = imageio.get_writer(save_path, fps=self.fps)
|
| 178 |
|
| 179 |
# Write frames to the video file
|
| 180 |
-
# for frame in wide_list[2:-1]:
|
| 181 |
for frame in wide_list:
|
| 182 |
video_writer.append_data(frame)
|
| 183 |
|
|
@@ -213,54 +190,6 @@ class Visualizer:
|
|
| 213 |
# process input video
|
| 214 |
for rgb in video:
|
| 215 |
res_video.append(rgb.copy())
|
| 216 |
-
# vector_colors = np.zeros((T, N, 3))
|
| 217 |
-
|
| 218 |
-
# if self.mode == "optical_flow":
|
| 219 |
-
# import flow_vis
|
| 220 |
-
|
| 221 |
-
# vector_colors = flow_vis.flow_to_color(tracks - tracks[query_frame][None])
|
| 222 |
-
# elif segm_mask is None:
|
| 223 |
-
# if self.mode == "rainbow":
|
| 224 |
-
# y_min, y_max = (
|
| 225 |
-
# tracks[query_frame, :, 1].min(),
|
| 226 |
-
# tracks[query_frame, :, 1].max(),
|
| 227 |
-
# )
|
| 228 |
-
# norm = plt.Normalize(y_min, y_max)
|
| 229 |
-
# for n in range(N):
|
| 230 |
-
# if isinstance(query_frame, torch.Tensor):
|
| 231 |
-
# query_frame_ = query_frame[n]
|
| 232 |
-
# else:
|
| 233 |
-
# query_frame_ = query_frame
|
| 234 |
-
# color = self.color_map(norm(tracks[query_frame_, n, 1]))
|
| 235 |
-
# color = np.array(color[:3])[None] * 255
|
| 236 |
-
# vector_colors[:, n] = np.repeat(color, T, axis=0)
|
| 237 |
-
# else:
|
| 238 |
-
# # color changes with time
|
| 239 |
-
# for t in range(T):
|
| 240 |
-
# color = np.array(self.color_map(t / T)[:3])[None] * 255
|
| 241 |
-
# vector_colors[t] = np.repeat(color, N, axis=0)
|
| 242 |
-
# else:
|
| 243 |
-
# if self.mode == "rainbow":
|
| 244 |
-
# vector_colors[:, segm_mask <= 0, :] = 255
|
| 245 |
-
|
| 246 |
-
# y_min, y_max = (
|
| 247 |
-
# tracks[0, segm_mask > 0, 1].min(),
|
| 248 |
-
# tracks[0, segm_mask > 0, 1].max(),
|
| 249 |
-
# )
|
| 250 |
-
# norm = plt.Normalize(y_min, y_max)
|
| 251 |
-
# for n in range(N):
|
| 252 |
-
# if segm_mask[n] > 0:
|
| 253 |
-
# color = self.color_map(norm(tracks[0, n, 1]))
|
| 254 |
-
# color = np.array(color[:3])[None] * 255
|
| 255 |
-
# vector_colors[:, n] = np.repeat(color, T, axis=0)
|
| 256 |
-
|
| 257 |
-
# else:
|
| 258 |
-
# # color changes with segm class
|
| 259 |
-
# segm_mask = segm_mask.cpu()
|
| 260 |
-
# color = np.zeros((segm_mask.shape[0], 3), dtype=np.float32)
|
| 261 |
-
# color[segm_mask > 0] = np.array(self.color_map(1.0)[:3]) * 255.0
|
| 262 |
-
# color[segm_mask <= 0] = np.array(self.color_map(0.0)[:3]) * 255.0
|
| 263 |
-
# vector_colors = np.repeat(color[None], T, axis=0)
|
| 264 |
|
| 265 |
# draw tracks
|
| 266 |
if self.tracks_leave_trace != 0:
|
|
@@ -306,10 +235,6 @@ class Visualizer:
|
|
| 306 |
visibile = True
|
| 307 |
else:
|
| 308 |
visibile = False
|
| 309 |
-
# if visibility is not None:
|
| 310 |
-
# visibile = visibility[0, j, i]
|
| 311 |
-
# if visibility[0, t, i] is False:
|
| 312 |
-
# visibile = False
|
| 313 |
if coord[0] != 0 and coord[1] != 0:
|
| 314 |
if not compensate_for_camera_motion or (
|
| 315 |
compensate_for_camera_motion and segm_mask[i] > 0
|
|
@@ -318,7 +243,6 @@ class Visualizer:
|
|
| 318 |
img,
|
| 319 |
coord=coord,
|
| 320 |
radius=int(self.linewidth * 2),
|
| 321 |
-
# color=vector_colors[t, points_map[i]-1].astype(int),
|
| 322 |
color=colors[points_map[i]-1],
|
| 323 |
visible=visibile,
|
| 324 |
color_alpha=color_alpha,
|
|
|
|
| 28 |
return np.stack(frames)
|
| 29 |
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
def draw_circle(rgb, coord, radius, color=(255, 0, 0), visible=True, color_alpha=None):
|
| 32 |
# Create a draw object
|
| 33 |
if not visible:
|
|
|
|
| 75 |
):
|
| 76 |
self.mode = mode
|
| 77 |
self.save_dir = save_dir
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
self.show_first_frame = show_first_frame
|
| 79 |
self.grayscale = grayscale
|
| 80 |
self.tracks_leave_trace = tracks_leave_trace
|
|
|
|
| 155 |
video_writer = imageio.get_writer(save_path, fps=self.fps)
|
| 156 |
|
| 157 |
# Write frames to the video file
|
|
|
|
| 158 |
for frame in wide_list:
|
| 159 |
video_writer.append_data(frame)
|
| 160 |
|
|
|
|
| 190 |
# process input video
|
| 191 |
for rgb in video:
|
| 192 |
res_video.append(rgb.copy())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
|
| 194 |
# draw tracks
|
| 195 |
if self.tracks_leave_trace != 0:
|
|
|
|
| 235 |
visibile = True
|
| 236 |
else:
|
| 237 |
visibile = False
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
if coord[0] != 0 and coord[1] != 0:
|
| 239 |
if not compensate_for_camera_motion or (
|
| 240 |
compensate_for_camera_motion and segm_mask[i] > 0
|
|
|
|
| 243 |
img,
|
| 244 |
coord=coord,
|
| 245 |
radius=int(self.linewidth * 2),
|
|
|
|
| 246 |
color=colors[points_map[i]-1],
|
| 247 |
visible=visibile,
|
| 248 |
color_alpha=color_alpha,
|