Ejemplo n.º 1
0
    def __init__(self,
                 frame_callback=None,
                 connection_callback=None,
                 calibrate=True,
                 state_function=None,
                 blocking=True):
        """
        Starts the RGBD streamer object

        The parameters are the following:

        - frame_callback: a callback function this object will call whenever a new calibrated RGBD frame is available
        - connection_callback: this is called whenever there is an update in the connection.
        - calibrate: Whether to calibrate the RGB-D data or not. If not, then the only thing it's retrieved are the
                     RGB and Depth frames.
        - stateFunction: This is a function which this module calls as soon as a new RGB-D frame is read. It is useful
                     to capture external information with timing as close as possible to the timing a frame is read
        """
        # Configuring the behavior
        self.frame_callback = frame_callback
        self.connection_callback = connection_callback
        self.calibrate = calibrate
        self.state_function = state_function
        self.blocking = blocking  # Blocking behavior for the caller application
        # Inner states
        self.streamLoopRunning = True
        self.paused = False
        self.delta = False

        # The source object for recorded RGB-D data. Devices data sources are handled inside pclStreamer
        self.recordedSource = None
        # The object with the relevant calibration data
        self.KDH = RGBDCamera()
        # By providing the references to the PCLStreamer of the cameras, it should be enough to do the calibration
        self.pclStreamer.setCameras(self.KDH.rgb_camera, self.KDH.depth_camera)
        self.connected = False
        self.N_frames = 100
        # The fifo of frames
        self.FIFO = deque()
        self.frameLock = Lock()
        self.recordingsLock = Lock()
        self.frameIndex = -1

        # Inner thread which is retrieving calibrated frames
        self.streamThread = Thread(target=self.streamLoop)
        self.streamThread.start()

        # Inner thread which is reading recorded RGB-D data (e.g. video files). Emulates a behavior like OpenNI but,
        # due to python restrictions, it would still run in the same CPU as the main thread
        self.RGBDReadThread = Thread(target=self.readRecordedLoop)
        self.RGBDReadThread.start()