Ejemplo n.º 1
0
    def refresh_data(self):
        # Get raw data.
        self._found_kinect, self._rgb, self._depth = kinect.get_buffers()

        # Perform basic data extraction.
        self._obstacles = kinect.extract_obstacles(self._depth, band=GAMING_DETECTION_ZONE, provide_raw=True)

        # Convert numpy arrays to cairo surfaces.
        alpha_channel = numpy.ones((480, 640, 1), dtype=numpy.uint8) * 255

        # 1. RGB bitmap.
        rgb32 = numpy.concatenate((alpha_channel, self._rgb), axis=2)
        self._rgb_surface = cairo.ImageSurface.create_for_data(
            rgb32[:, :, ::-1].astype(numpy.uint8), cairo.FORMAT_ARGB32, 640, 480
        )

        # 2. Depth map, take care of special NaN value.
        i = numpy.amin(self._depth)
        depth_clean = numpy.where(self._depth == kinect.UNDEF_DEPTH, 0, self._depth)
        a = numpy.amax(depth_clean)
        depth = numpy.where(self._depth == kinect.UNDEF_DEPTH, 0, 255 - (self._depth - i) * 254.0 / (a - i))
        depth32 = numpy.dstack((alpha_channel, depth, numpy.where(depth == 0, 128, depth), depth))
        self._depth_surface = cairo.ImageSurface.create_for_data(
            depth32[:, :, ::-1].astype(numpy.uint8), cairo.FORMAT_ARGB32, 640, 480
        )

        self._notify_observers()
Ejemplo n.º 2
0
    def _timedout(self):
        # Stop auto refresh if no Kinect is detected.
        found_kinect, _, _ = kinect.get_buffers()
        if found_kinect:
            self._display.refresh_data()
            self.queue_draw()
        else:
            if not self._paused:
                print 'No Kinect found, stopping auto-refresh'
                self._pause_cb(None, True)

        # Timer is repeated until False is returned.
        return not self._paused