Skip to content

Commit

Permalink
implement option to visualize detection IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
timmh committed Sep 20, 2023
1 parent 16240e0 commit 6f65c1a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Config:

# visualization parameters
make_figures: bool = True # save figures in results directory
draw_detection_ids: bool = False # whether to annotate detection IDs over detected bounding boxes
draw_world_position: bool = False # whether to annotate estimated world position over detected bounding boxes

# calibration parameters
Expand Down
2 changes: 1 addition & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def run(config: Config):


if config.make_figures:
visualize_detection(config.data_dir, detection_id, img, depth, farthest_calibration_frame_disp, boxes, masks, world_positions, sample_locations, config.draw_world_position, config.min_depth, config.max_depth)
visualize_detection(config.data_dir, detection_id, img, depth, farthest_calibration_frame_disp, boxes, masks, world_positions, sample_locations, config.draw_detection_ids, config.draw_world_position, config.min_depth, config.max_depth)

yield

Expand Down
12 changes: 8 additions & 4 deletions visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def visualize_farthest_calibration_frame_impl(data_dir, transect_id, farthest_ca
)


def visualize_detection_impl(data_dir, detection_id, detection_frame, calibrated_depth_midas, farthest_calibration_frame_disp, boxes, masks, world_positions, sample_locations, draw_world_position, min_depth, max_depth):
def visualize_detection_impl(data_dir, detection_id, detection_frame, calibrated_depth_midas, farthest_calibration_frame_disp, boxes, masks, world_positions, sample_locations, draw_detection_ids, draw_world_position, min_depth, max_depth):
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.patches
Expand All @@ -84,7 +84,7 @@ def visualize_detection_impl(data_dir, detection_id, detection_frame, calibrated

ax1.imshow(detection_frame[..., ::-1])
ax1.set_title("Observation")
for box, mask, world_pos in zip(boxes, masks, world_positions):
for i, (box, mask, world_pos) in enumerate(zip(boxes, masks, world_positions)):
if mask is not None:
mask_rgb = np.zeros((*detection_frame.shape[0:2], 4))
mask_rgb[:, :, [0, 3]] = mask[..., None]
Expand All @@ -99,9 +99,13 @@ def visualize_detection_impl(data_dir, detection_id, detection_frame, calibrated
facecolor="none",
)
ax1.add_patch(rect)
label = ""
if draw_detection_ids:
label += f"#{i:03d}"
if draw_world_position:
rx, ry = rect.get_xy()
ax1.annotate(",".join([f"{e:.2f}m" for e in world_pos]), (rx, ry - 5), color="red", fontsize=6)
label += "@" + ",".join([f"{e:.2f}m" for e in world_pos])
rx, ry = rect.get_xy()
ax1.annotate(label, (rx, ry - 5), color="red", fontsize=6)
ax1.get_xaxis().set_visible(False)
ax1.get_yaxis().set_visible(False)
im = ax2.imshow(calibrated_depth_midas, vmin=min_depth, vmax=max_depth, cmap="turbo")
Expand Down

0 comments on commit 6f65c1a

Please sign in to comment.