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