Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render_annotation fixed #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions lyft_dataset_sdk/lyftdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -1062,8 +1062,7 @@ def render_annotation(

fig, axes = plt.subplots(1, 2, figsize=(18, 9))

# Figure out which camera the object is fully visible in (this may return nothing)
boxes, cam = [], []
# Figure out which camera the object is visible in, with the given `box_vis_level` (this may return nothing)
cams = [key for key in sample_record["data"].keys() if "CAM" in key]
for cam in cams:
_, boxes, _ = self.lyftd.get_sample_data(
Expand All @@ -1080,14 +1079,15 @@ def render_annotation(
lidar = sample_record["data"]["LIDAR_TOP"]
data_path, boxes, camera_intrinsic = self.lyftd.get_sample_data(lidar, selected_anntokens=[ann_token])
LidarPointCloud.from_file(data_path).render_height(axes[0], view=view)
for box in boxes:
c = np.array(self.get_color(box.name)) / 255.0
box.render(axes[0], view=view, colors=(c, c, c))
corners = view_points(boxes[0].corners(), view, False)[:2, :]
axes[0].set_xlim([np.min(corners[0, :]) - margin, np.max(corners[0, :]) + margin])
axes[0].set_ylim([np.min(corners[1, :]) - margin, np.max(corners[1, :]) + margin])
axes[0].axis("off")
axes[0].set_aspect("equal")
box = boxes[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it would be great to add an assert or write in a way that will fail in case there are more than one boxes, e.g.

Suggested change
box = boxes[0]
box, = boxes

and same with removing the loop below.

c = np.array(self.get_color(box.name)) / 255.0
box.render(axes[0], view=view, colors=(c, c, c))
corners = view_points(box.corners(), view, False)[:2, :]
axes[0].set_xlim([np.min(corners[0, :]) - margin, np.max(corners[0, :]) + margin])
axes[0].set_ylim([np.min(corners[1, :]) - margin, np.max(corners[1, :]) + margin])
axes[0].set_title("LIDAR_TOP")
axes[0].axis("off")
axes[0].set_aspect("equal")

# Plot CAMERA view
data_path, boxes, camera_intrinsic = self.lyftd.get_sample_data(cam, selected_anntokens=[ann_token])
Expand All @@ -1096,9 +1096,9 @@ def render_annotation(
axes[1].set_title(self.lyftd.get("sample_data", cam)["channel"])
axes[1].axis("off")
axes[1].set_aspect("equal")
for box in boxes:
c = np.array(self.get_color(box.name)) / 255.0
box.render(axes[1], view=camera_intrinsic, normalize=True, colors=(c, c, c))
box = boxes[0]
c = np.array(self.get_color(box.name)) / 255.0
box.render(axes[1], view=camera_intrinsic, normalize=True, colors=(c, c, c))

if out_path is not None:
plt.savefig(out_path)
Expand Down