Skip to content

Commit

Permalink
get_width/height of cameras & save original camera matrix
Browse files Browse the repository at this point in the history
Add `get_width`/`get_height` to the Camera classes and store the
original camera matrix in CalibratedCamera.  This is to make it easier
to access this information in the PyBullet driver implemented in
trifinger_cameras.
  • Loading branch information
luator committed Aug 20, 2024
1 parent 6e9b504 commit c594db7
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions trifinger_simulation/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,15 @@ class BaseCamera:
def get_image(
self, renderer=pybullet.ER_BULLET_HARDWARE_OPENGL
) -> np.ndarray:
"""Render an image."""
raise NotImplementedError()

def get_width(self) -> int:
"""Get width of the images rendered by this camera instance."""
raise NotImplementedError()

def get_height(self) -> int:
"""Get height of the images rendered by this camera instance."""
raise NotImplementedError()


Expand Down Expand Up @@ -197,6 +206,12 @@ def __init__(
physicsClientId=self._pybullet_client_id,
)

def get_width(self) -> int:
return self._width

def get_height(self) -> int:
return self._height

def get_image(
self, renderer=pybullet.ER_BULLET_HARDWARE_OPENGL
) -> np.ndarray:
Expand Down Expand Up @@ -285,6 +300,9 @@ def __init__(
pybullet_client_id: Id of the pybullet client (needed when
multiple clients are running in parallel).
"""
# store the original camera matrix for use in C++ bindings (trifinger_cameras)
self._original_camera_matrix = camera_matrix

self._pybullet_client_id = pybullet_client_id

#: Width of the output images.
Expand Down Expand Up @@ -359,6 +377,12 @@ def __init__(
)
self._proj_matrix = proj_mat.flatten(order="F")

def get_width(self) -> int:
return self._output_width

def get_height(self) -> int:
return self._output_height

def distort_image(self, image):
"""Distort an image based on the cameras distortion coefficients.
Expand Down

0 comments on commit c594db7

Please sign in to comment.