Exemple #1
0
def test_pixel_has_same_depth(x, y, z, threshold, expected):
    """Tests if the pixel at (x,y) has a depth within the specified
       threshold of z."""
    camera_setup = None
    depth_frame = DepthFrame([[0, 0.1, 0], [0, 0, 0.5]], camera_setup)
    assert depth_frame.pixel_has_same_depth(x, y, z, threshold) is expected, \
           "Depth thresholding did not work correctly."
Exemple #2
0
def test_get_pixel_locations(depth_frame, pixels, expected):
    height, width = depth_frame.shape
    camera_setup = CameraSetup('test_setup',
                               'test_type',
                               width,
                               height,
                               Transform(location=Location(0, 0, 0),
                                         rotation=Rotation(0, 0, 0)),
                               fov=90)
    depth_frame = DepthFrame(depth_frame, camera_setup)
    locations = depth_frame.get_pixel_locations(pixels)
    for i in range(len(pixels)):
        assert np.isclose(locations[i].x, expected[i].x), 'Returned x '
        'value is not the same as expected'
        assert np.isclose(locations[i].y, expected[i].y), 'Returned y '
        'value is not the same as expected'
        assert np.isclose(locations[i].z, expected[i].z), 'Returned z '
        'value is not the same as expected'
Exemple #3
0
def test_depth_to_point_cloud(depth_frame, expected):
    height, width = depth_frame.shape
    camera_setup = CameraSetup('test_setup',
                               'test_type',
                               width,
                               height,
                               Transform(location=Location(0, 0, 0),
                                         rotation=Rotation(0, 0, 0)),
                               fov=90)
    depth_frame = DepthFrame(depth_frame, camera_setup)
    # Resulting unreal coordinates.
    point_cloud = depth_frame.as_point_cloud()
    for i in range(width * height):
        assert np.isclose(point_cloud[i].x, expected[i].x), 'Returned x '
        'value is not the same as expected'
        assert np.isclose(point_cloud[i].y, expected[i].y), 'Returned y '
        'value is not the same as expected'
        assert np.isclose(point_cloud[i].z, expected[i].z), 'Returned z '
        'value is not the same as expected'
Exemple #4
0
def test_depth_to_point_cloud(depth_frame, expected):
    height, width = depth_frame.shape
    camera_setup = CameraSetup('test_setup',
                               'sensor.camera.depth',
                               width,
                               height,
                               Transform(location=Location(0, 0, 0),
                                         rotation=Rotation(0, 0, 0)),
                               fov=90)
    depth_frame = DepthFrame(depth_frame, camera_setup)
    # Resulting unreal coordinates.
    point_cloud = depth_frame.as_point_cloud()
    for i in range(width * height):
        assert np.isclose(point_cloud[i][0], expected[i][0]), \
            'Returned x value is not the same as expected'
        assert np.isclose(point_cloud[i][1], expected[i][1]), \
            'Returned y value is not the same as expected'
        assert np.isclose(point_cloud[i][2], expected[i][2]), \
            'Returned z value is not the same as expected'
Exemple #5
0
    def compute_depth(self, timestamp, depth_estimation_stream):
        self._logger.debug('@{}: {} received watermark'.format(
            timestamp, self._name))
        start_time = time.time()

        imgL = self._left_imgs.pop(timestamp)
        imgR = self._right_imgs.pop(timestamp)

        cudnn.benchmark = False
        self._model.eval()
        imgL = imgL.float().cuda().unsqueeze(0)
        imgR = imgR.float().cuda().unsqueeze(0)
        with torch.no_grad():
            outputs = self._model(imgL, imgR)
            output = torch.squeeze(outputs[2], 1)
        output = output.squeeze().cpu().numpy()
        # Process the output (disparity) to depth, model-dependent
        depth = preprocess.disp2depth(output)
        # Get runtime in ms.
        runtime = (time.time() - start_time) * 1000
        self._csv_logger.info('{},{},"{}",{}'.format(time_epoch_ms(),
                                                     self._name, timestamp,
                                                     runtime))

        if self._flags.visualize_depth_est:
            cv2.imshow(self._name, output)
            cv2.waitKey(1)

        camera_setup = CameraSetup("depth_estimation",
                                   "estimation.anynet",
                                   depth.shape[1],
                                   depth.shape[0],
                                   self._transform,
                                   fov=self._fov)
        depth_estimation_stream.send(
            DepthFrameMessage(DepthFrame(depth, camera_setup), timestamp))