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

Enable passing and receiving subplots for viz #1416

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion perception/fairotag/python/fairotag/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def render_markers(self, img, markers=None):
tvec = m.pose.translation()[None, :]
rvec = m.pose.so3().log()[None, :]
length = m.length / 2.0
img_rend = cv2.aruco.drawAxis(
img_rend = cv2.drawFrameAxes(
img_rend,
self._intrinsics2matrix(self.intrinsics),
self.intrinsics.coeffs,
Expand Down
10 changes: 6 additions & 4 deletions perception/fairotag/python/fairotag/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Object:
pose_in_frame: sp.SE3
size: float
is_anchor: bool = False
is_visible: bool = False
is_visible: bool = True


@dataclass
Expand Down Expand Up @@ -64,6 +64,7 @@ def __init__(self, camera_noise=None, calib_noise=None):

# Default world frame
f0 = Frame("world", sp.SE3())
f0.is_visible = True
self._frames["world"] = f0

# Scene construction
Expand Down Expand Up @@ -344,8 +345,8 @@ def calibrate_extrinsics(
self.clear_snapshots()

# Rendering
def visualize(self, show_marker_id=False):
viz = SceneViz()
def visualize(self, fig=None, show_marker_id=False, should_return=False):
viz = SceneViz(fig=fig)

# Draw markers & cameras
for obj_name, obj in self._objects.items():
Expand All @@ -358,14 +359,15 @@ def visualize(self, show_marker_id=False):
else:
viz.draw_camera(obj.pose, size=obj.size)


# Draw frames
for frame_name, frame in self._frames.items():
if not frame.is_visible:
continue
viz.draw_axes(frame.pose)

# Show
viz.show()
return viz.show(should_return=should_return)

# Save / Load TODO
def __getstate__(self):
Expand Down
22 changes: 15 additions & 7 deletions perception/fairotag/python/fairotag/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
import sophus as sp
import matplotlib.pyplot as plt

DEFAULT_AXIS_LENGTH = 0.1
DEFAULT_AXIS_LENGTH = 0.3


class SceneViz:
def __init__(self):
self.fig = plt.figure()
self.ax = plt.axes(projection="3d")
def __init__(self, fig=None, plot_config=112):
self.fig=None
if fig:
self.fig = fig
else:
self.fig = plt.figure()
self.ax = self.fig.add_subplot(1,2,2,projection="3d")
self.max = np.zeros(3)
self.min = np.zeros(3)

Expand Down Expand Up @@ -80,13 +84,17 @@ def draw_marker(self, pose, id, length, color="k", show_id=False):
pos = pose.translation()
self.ax.text(pos[0], pos[1], pos[2], id, color="b")

def show(self):
def show(self, should_return=False):
# Set limits
mid = (self.max + self.min) / 2.0
r = max(np.max(self.max - mid), np.max(mid - self.min))
self.ax.set_xlim(mid[0] - r, mid[0] + r)
self.ax.set_ylim(mid[1] - r, mid[1] + r)
self.ax.set_zlim(mid[2] - r, mid[2] + r)

# Show
plt.show()
if should_return:
return self.ax
else:
# Show
plt.show()
return None
Loading