Get compressed frames.

This commit is contained in:
Simon Le Goff 2024-11-25 19:40:26 +01:00
parent 03a44a56f3
commit 81fadfb569
1 changed files with 25 additions and 16 deletions

View File

@ -39,39 +39,48 @@ class ReachyCameraConfig:
class ReachyCamera: class ReachyCamera:
def __init__(self, host: str, port: int,name: str, image_type: str, config: ReachyCameraConfig | None = None, **kwargs): def __init__(
self.host=host self,
self.port=port host: str,
port: int,
name: str,
image_type: str,
config: ReachyCameraConfig | None = None,
**kwargs
):
self.host = host
self.port = port
self.image_type = image_type self.image_type = image_type
self.name = name self.name = name
self.config = config self.config = config
self.cam_manager=None self.cam_manager = None
self.is_connected = False self.is_connected = False
self.logs = {} self.logs = {}
def connect(self): def connect(self):
if not self.is_connected: if not self.is_connected:
self.cam_manager=CameraManager(host=self.host, port=self.port) self.cam_manager = CameraManager(host=self.host, port=self.port)
self.cam_manager.initialize_cameras()#FIXME: maybe we should not re-initialize self.cam_manager.initialize_cameras() # FIXME: maybe we should not re-initialize
self.is_connected=True self.is_connected = True
def read(self) -> np.ndarray: def read(self) -> np.ndarray:
if not self.is_connected: if not self.is_connected:
self.connect() self.connect()
if self.name=='teleop' and hasattr(self.cam_manager,'teleop'): if self.name == "teleop" and hasattr(self.cam_manager, "teleop"):
if self.image_type=='left': if self.image_type == "left":
return self.cam_manager.teleop.get_frame(CameraView.LEFT) return self.cam_manager.teleop.get_compressed_frame(CameraView.LEFT)
elif self.image_type=='right': elif self.image_type == "right":
return self.cam_manager.teleop.get_frame(CameraView.RIGHT) return self.cam_manager.teleop.get_compressed_frame(CameraView.RIGHT)
else: else:
return None return None
elif self.name=='depth' and hasattr(self.cam_manager,'depth'): elif self.name == "depth" and hasattr(self.cam_manager, "depth"):
if self.image_type=='depth': if self.image_type == "depth":
return self.cam_manager.depth.get_depth_frame() return self.cam_manager.depth.get_depth_frame()
elif self.image_type=='rgb': elif self.image_type == "rgb":
return self.cam_manager.depth.get_frame() return self.cam_manager.depth.get_compressed_frame()
else: else:
return None return None
return None