Exemple #1
0
    def _start_kinect(self):
        if self.device == 'kinect':
            freenect.sync_get_depth() #Grabbing a frame initializes the device
            freenect.sync_get_video()

        elif self.device == 'kinect2':
            # a: Identify pipeline to use: 1) OpenGL, 2) OpenCL, 3) CPU
            try:
                self.pipeline = FN2.OpenCLPacketPipeline()
            except:
                try:
                    self.pipeline = FN2.OpenGLPacketPipeline()
                except:
                    self.pipeline = FN2.CpuPacketPipeline()
            self._print('PacketPipeline: ' + type(self.pipeline).__name__)

            # b: Create and set logger
            self.logger = FN2.createConsoleLogger(FN2.LoggerLevel.NONE)
            FN2.setGlobalLogger(self.logger)

            # c: Identify device and create listener
            self.fn = FN2.Freenect2()
            serial = self.fn.getDeviceSerialNumber(0)
            self.K2device = self.fn.openDevice(serial, pipeline=self.pipeline)

            self.listener = FN2.SyncMultiFrameListener(
                FN2.FrameType.Color | FN2.FrameType.Depth)
            # d: Register listeners
            self.K2device.setColorFrameListener(self.listener)
            self.K2device.setIrAndDepthFrameListener(self.listener)
            # e: Start device and create registration
            self.K2device.start()
            self.registration = FN2.Registration(self.K2device.getIrCameraParams(), self.K2device.getColorCameraParams())
Exemple #2
0
    def start(self):
        """Starts the Kinect v2 sensor stream.

        Raises
        ------
        IOError
            If the Kinect v2 is not detected.
        """
        # open packet pipeline
        if self._packet_pipeline_mode == Kinect2PacketPipelineMode.OPENGL:
            self._pipeline = lf2.OpenGLPacketPipeline()
        elif self._packet_pipeline_mode == Kinect2PacketPipelineMode.CPU:
            self._pipeline = lf2.CpuPacketPipeline()

        # setup logger
        self._logger = lf2.createConsoleLogger(lf2.LoggerLevel.Warning)
        lf2.setGlobalLogger(self._logger)

        # check devices
        self._fn_handle = lf2.Freenect2()
        self._num_devices = self._fn_handle.enumerateDevices()
        if self._num_devices == 0:
            raise IOError(
                'Failed to start stream. No Kinect2 devices available!')
        if self._num_devices <= self._device_num:
            raise IOError(
                'Failed to start stream. Device num %d unavailable!' %
                (self._device_num))

        # open device
        self._serial = self._fn_handle.getDeviceSerialNumber(self._device_num)
        self._device = self._fn_handle.openDevice(self._serial,
                                                  pipeline=self._pipeline)

        # add device sync modes
        self._listener = lf2.SyncMultiFrameListener(lf2.FrameType.Color
                                                    | lf2.FrameType.Ir
                                                    | lf2.FrameType.Depth)
        self._device.setColorFrameListener(self._listener)
        self._device.setIrAndDepthFrameListener(self._listener)

        # start device
        self._device.start()

        # open registration
        self._registration = None
        if self._registration_mode == Kinect2RegistrationMode.COLOR_TO_DEPTH:
            logging.debug('Using color to depth registration')
            self._registration = lf2.Registration(
                self._device.getIrCameraParams(),
                self._device.getColorCameraParams())
        self._running = True
    def start(self):
        """Starts the Kinect v2 sensor stream.

        Raises
        ------
        IOError
            If the Kinect v2 is not detected.
        """

        # setup logger
        self._logger = lf2.createConsoleLogger(lf2.LoggerLevel.Warning)
        lf2.setGlobalLogger(self._logger)

        # open packet pipeline
        self._pipeline = None
        if (self._packet_pipeline_mode == Kinect2PacketPipelineMode.OPENGL or
                self._packet_pipeline_mode == Kinect2PacketPipelineMode.AUTO):
            # Try OpenGL packet pipeline first or if specified
            try:
                self._pipeline = lf2.OpenGLPacketPipeline()
            except BaseException:
                logging.warning("OpenGL not available. "
                                "Defaulting to CPU-based packet pipeline.")

        if self._pipeline is None and (self._packet_pipeline_mode
                                       == Kinect2PacketPipelineMode.OPENCL
                                       or self._packet_pipeline_mode
                                       == Kinect2PacketPipelineMode.AUTO):
            # Try OpenCL if available
            try:
                self._pipeline = lf2.OpenCLPacketPipeline()
            except BaseException:
                logging.warning(
                    "OpenCL not available. Defaulting to CPU packet pipeline.")

        if (self._pipeline is None or self._packet_pipeline_mode
                == Kinect2PacketPipelineMode.CPU):  # CPU packet pipeline
            self._pipeline = lf2.CpuPacketPipeline()

        # check devices
        self._fn_handle = lf2.Freenect2()
        self._num_devices = self._fn_handle.enumerateDevices()
        if self._num_devices == 0:
            raise IOError(
                "Failed to start stream. No Kinect2 devices available!")
        if self._num_devices <= self._device_num:
            raise IOError(
                "Failed to start stream. Device num %d unavailable!" %
                (self._device_num))

        # open device
        self._serial = self._fn_handle.getDeviceSerialNumber(self._device_num)
        self._device = self._fn_handle.openDevice(self._serial,
                                                  pipeline=self._pipeline)

        # add device sync modes
        self._listener = lf2.SyncMultiFrameListener(lf2.FrameType.Color
                                                    | lf2.FrameType.Ir
                                                    | lf2.FrameType.Depth)
        self._device.setColorFrameListener(self._listener)
        self._device.setIrAndDepthFrameListener(self._listener)

        # start device
        self._device.start()

        # open registration
        self._registration = None
        if self._registration_mode == Kinect2RegistrationMode.COLOR_TO_DEPTH:
            logging.debug("Using color to depth registration")
            self._registration = lf2.Registration(
                self._device.getIrCameraParams(),
                self._device.getColorCameraParams(),
            )
        self._running = True