
    *iU                         d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	m
Z
 ddlZe G d d                      Z G d	 d
e          ZdS )z6Abstract camera interface for recording and conversion    )ABCabstractmethod)	dataclass)Path)OptionalTupleNc                   R    e Zd ZU dZej        ed<   eej                 ed<   eed<   dS )CameraFramezA single camera framecolordepthtimestamp_nsN)	__name__
__module____qualname____doc__npndarray__annotations__r   int     1/home/robot-lab/raiden_cmu/raiden/cameras/base.pyr
   r
      sE         :BJr   r
   c                      e Zd ZdZeedefd                        Zeedefd                        Zeedefd                        Z	edd            Z
edd            Zed	eddfd
            Zedd            Zedefd            Zedefd            ZdefdZedeej        ej        eeef         f         fd            ZdS )Camerau   Abstract base class for cameras.

    Supports two usage modes:
    - Live recording: open() → start_recording(path) → grab() loop → stop_recording() → close()
    - File playback: open_file(path) → grab() loop → get_frame() → close()
    returnc                     dS )z;Semantic name assigned to this camera (e.g. 'scene_camera')Nr   selfs    r   namezCamera.name   	     	r   c                     dS )z'Camera hardware serial number as stringNr   r   s    r   serial_numberzCamera.serial_number"   r    r   c                     dS )z=File extension used for native recording (e.g. 'svo2', 'bag')Nr   r   s    r   recording_extensionzCamera.recording_extension(   r    r   Nc                     dS )zOpen live camera connectionNr   r   s    r   openzCamera.open.   	     	r   c                     dS )z&Close camera and release all resourcesNr   r   s    r   closezCamera.close3   r'   r   pathc                     dS )zBegin recording to file.

        For ZED this enables SVO2 recording; every subsequent grab() is stored.
        For RealSense this starts a .bag recorder.
        Nr   )r   r*   s     r   start_recordingzCamera.start_recording8   s	     	r   c                     dS )z+Stop recording and finalize the output fileNr   r   s    r   stop_recordingzCamera.stop_recordingA   r'   r   c                     dS )a
  Grab the next available frame.

        Blocks until a frame is ready (rate-limited to camera FPS).
        While recording is active, the frame is also written to the output file.

        Returns:
            True on success, False on error or end-of-file
        Nr   r   s    r   grabzCamera.grabF   s	     	r   c                     dS )z~Retrieve color and depth from the most recently grabbed frame.

        Only valid to call after a successful grab().
        Nr   r   s    r   	get_framezCamera.get_frameR   s	     	r   c                 2    ddl }|                                S )al  Current host time in nanoseconds.

        The default implementation uses ``time.time_ns()``.  Camera subclasses
        that have their own hardware clock (e.g. ZED) should override this so
        that the returned value is on the *same clock* as ``CameraFrame.timestamp_ns``,
        enabling direct interpolation between robot data and camera frames.
        r   N)timetime_ns)r   r4   s     r   get_current_timestamp_nszCamera.get_current_timestamp_nsZ   s     	||~~r   c                     dS )a  Return factory-calibrated camera intrinsics.

        These come directly from the camera SDK (ZED factory calibration,
        RealSense on-device calibration) rather than being computed from images.

        Returns:
            camera_matrix: 3x3 float64 array ``[[fx,0,cx],[0,fy,cy],[0,0,1]]``
            dist_coeffs: 1-D float64 array ``[k1, k2, p1, p2, k3]`` (OpenCV Brown-Conrady)
            image_size: ``(width, height)`` in pixels
        Nr   r   s    r   get_intrinsicszCamera.get_intrinsicsf   s	     	r   )r   N)r   r   r   r   propertyr   strr   r"   r$   r&   r)   r   r,   r.   boolr0   r
   r2   r   r6   r   r   r   r8   r   r   r   r   r      s         c    ^ X s    ^ X S    ^ X    ^    ^ D T    ^    ^ 	d 	 	 	 ^	 ;    ^
# 
 
 
 
 bj"*eCHo&M N    ^  r   r   )r   abcr   r   dataclassesr   pathlibr   typingr   r   numpyr   r
   r   r   r   r   <module>rA      s    < < # # # # # # # # ! ! ! ! ! !       " " " " " " " "            ^ ^ ^ ^ ^S ^ ^ ^ ^ ^r   