示例#1
0
def loop(sock, camera, app, show=True):
    if show:
        color_window = NumpyWidget()
        color_window.show()
        depth_window = NumpyWidget()
        depth_window.show()

        colormap = numpy.float32(matplotlib.cm.jet(numpy.arange(1001) / 1000.0))

    n = 0
    clients = []

    try:
        mark = time()
        while True:
            # check for new clients
            check_connections(sock, clients)

            # read and process the camera frame
            try:
                frame = camera.read()
            except RuntimeError as e:
                logger.error('error while capturing frame')
                logger.error(traceback.format_exc())
                break

            color_buffer = frame.color.open(PixelFormat.RGB24)
            color_image = numpy.frombuffer(color_buffer.data(), dtype=numpy.uint8).reshape((color_buffer.height, color_buffer.width, -1))
            # BGR -> RGB
            color_image = color_image[:,:,::-1]

            try:
                cloud_buffer = frame.computePointCloud()
            except RuntimeError as e:
                logger.warn('{} -> skipping frame'.format(e))
                continue
            cloud = numpy.frombuffer(cloud_buffer, dtype=numpy.float32).reshape((frame.depth.height, frame.depth.width, 3))

            # send the frame
            if clients:
                send_frame(clients, (color_image, cloud))

            # update the view
            if show and (not clients or n % 10 == 0):
                color_window.update_frame(color_image)
                depth_window.update_frame(colormap[numpy.clip(cloud[:,:,2], 0, len(colormap) - 1).astype(numpy.int)])
                # process events for the windows
                app.processEvents()

            n += 1

            if n % 30 == 0:
                # print some debug stats
                fps = 30 / (time() - mark)
                mark = time()
                logger.debug('{:.1f} fps'.format(fps))

    except KeyboardInterrupt:
        pass

    for (conn, addr) in clients:
        conn.close()
        logger.info('closed connection with {}'.format(addr))
示例#2
0
def loop(sock, camera, show=True):
    if show:
        from ui.numpy_widget import NumpyWidget
        import matplotlib.cm
        from PySide.QtGui import QApplication

        app = QApplication(sys.argv)

        color_window = NumpyWidget()
        color_window.show()
        depth_window = NumpyWidget()
        depth_window.show()

        colormap = numpy.float32(matplotlib.cm.jet(
            numpy.arange(1001) / 1000.0))

    n = 0
    clients = []

    try:
        mark = time()
        while True:
            # check for new clients
            check_connections(sock, clients)

            # read and process the camera frame
            try:
                frame = camera.read()
            except RuntimeError as e:
                logger.error('error while capturing frame')
                logger.error(traceback.format_exc())
                break

            color_buffer = frame.color.open(PixelFormat.RGB24)
            color_image = numpy.frombuffer(color_buffer.data(),
                                           dtype=numpy.uint8).reshape(
                                               (color_buffer.height,
                                                color_buffer.width, -1))
            # BGR -> RGB
            color_image = color_image[:, :, ::-1]

            try:
                cloud_buffer = frame.computePointCloud()
            except RuntimeError as e:
                logger.warn('{} -> skipping frame'.format(e))
                continue
            cloud = numpy.frombuffer(cloud_buffer,
                                     dtype=numpy.float32).reshape(
                                         (frame.depth.height,
                                          frame.depth.width, 3))

            try:
                depth_uv_buffer = frame.computeDepthUVMap()
            except RuntimeError as e:
                logger.warn('{} -> skipping frame'.format(e))
                continue
            depth_uv = numpy.frombuffer(depth_uv_buffer,
                                        dtype=numpy.float32).reshape(
                                            (frame.depth.height,
                                             frame.depth.width, 2))

            try:
                color_uv_buffer = frame.computeColorUVMap()
            except RuntimeError as e:
                logger.warn('{} -> skipping frame'.format(e))
                continue
            inverse_uv = numpy.frombuffer(color_uv_buffer,
                                          dtype=numpy.float32).reshape(
                                              (color_buffer.height,
                                               color_buffer.width, 2))

            #color_image = numpy.empty((cloud.shape[0], cloud.shape[1], 3), dtype=numpy.uint8)
            #color_image[:,:] = [ 0, 255, 0 ]

            #depth_uv = numpy.empty((cloud.shape[0], cloud.shape[1], 2), dtype=numpy.float32)
            #depth_uv[:,:] = [ -1, -1 ]

            # send the frame
            if clients:
                send_frame(clients, (color_image, cloud, depth_uv, inverse_uv))

            # update the view
            if show and (not clients or n % 10 == 0):
                color_window.update_frame(color_image)
                depth_window.update_frame(colormap[numpy.clip(
                    cloud[:, :, 2], 0,
                    len(colormap) - 1).astype(numpy.int)])
                # process events for the windows
                app.processEvents()

            n += 1

            if n % 30 == 0:
                # print some debug stats
                fps = 30 / (time() - mark)
                mark = time()
                logger.debug('{:.1f} fps'.format(fps))

    except KeyboardInterrupt:
        pass

    for (conn, addr) in clients:
        conn.close()
        logger.info('closed connection with {}'.format(addr))
示例#3
0
    app = QApplication(sys.argv)
    color_window = NumpyWidget()
    color_window.show()
    depth_window = NumpyWidget()
    depth_window.show()

    colormap = numpy.float32(matplotlib.cm.jet(numpy.arange(1001) / 1000.0))

    n = 0

    try:
        mark = time()
        while True:
            (color, cloud, _, _) = camera.read()

            color_window.update_frame(color)
            depth_window.update_frame(colormap[numpy.clip(
                cloud[:, :, 2], 0,
                len(colormap) - 1).astype(numpy.int)])
            app.processEvents()

            n += 1

            if n % 30 == 0:
                # print some debug stats
                fps = 30 / (time() - mark)
                mark = time()
                logger.debug('{:.1f} fps'.format(fps))

    except KeyboardInterrupt:
        pass
示例#4
0
        color_window = NumpyWidget()
        color_window.show()
        depth_window = NumpyWidget()
        depth_window.show()

    colormap = numpy.float32(matplotlib.cm.jet(numpy.arange(1001) / 1000.0))

    n = 0

    try:
        mark = time()
        while True:
            (color, cloud, depth_uv, color_uv) = camera.read()

            if show:
                color_window.update_frame(color)
                depth_window.update_frame(colormap[numpy.clip(cloud[:,:,2], 0, len(colormap) - 1).astype(numpy.int)])
                app.processEvents()
                
            n += 1

            if n % 30 == 0:
                # print some debug stats
                fps = 30 / (time() - mark)
                mark = time()
                logger.debug('{:.1f} fps'.format(fps))

    except KeyboardInterrupt:
        pass

    camera.close()