From 97eb5b98f7a6fc39027bda16f3bf84a9060e98cf Mon Sep 17 00:00:00 2001 From: tom-bu Date: Mon, 26 Jul 2021 16:40:12 -0400 Subject: [PATCH 1/2] account for rounding in point cloud projection --- argoverse/utils/calibration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/argoverse/utils/calibration.py b/argoverse/utils/calibration.py index bcd4924c..b5234e62 100644 --- a/argoverse/utils/calibration.py +++ b/argoverse/utils/calibration.py @@ -376,8 +376,8 @@ def determine_valid_cam_coords(uv: np.ndarray, uv_cam: np.ndarray, camera_config Returns: Numpy array of shape (N,) with dtype bool """ - x_valid = np.logical_and(0 <= uv[:, 0], uv[:, 0] < camera_config.img_width) - y_valid = np.logical_and(0 <= uv[:, 1], uv[:, 1] < camera_config.img_height) + x_valid = np.logical_and(0 <= np.round(uv[:, 0]), np.round(uv[:, 0]) < camera_config.img_width) + y_valid = np.logical_and(0 <= np.round(uv[:, 1]), np.round(uv[:, 1]) < camera_config.img_height) z_valid = uv_cam[2, :] > 0 valid_pts_bool = np.logical_and(np.logical_and(x_valid, y_valid), z_valid) return valid_pts_bool From 8187a802d8c70de3f9643d5b17286bde6ecc7de3 Mon Sep 17 00:00:00 2001 From: tom-bu Date: Tue, 27 Jul 2021 02:04:12 -0400 Subject: [PATCH 2/2] add unit test --- tests/test_valid_pt_cloud_proj.py | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tests/test_valid_pt_cloud_proj.py diff --git a/tests/test_valid_pt_cloud_proj.py b/tests/test_valid_pt_cloud_proj.py new file mode 100644 index 00000000..5a41174d --- /dev/null +++ b/tests/test_valid_pt_cloud_proj.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +@author: tom-bu +""" + +import numpy as np + +from argoverse.utils.calibration import CameraConfig, determine_valid_cam_coords + + +def test_valid_point_cloud_projections() -> None: + """Test to ensure determine_valid_cam_coords() returns valid points that are less than the image width and height.""" + # create a fake camera config + camera_config = CameraConfig( + extrinsic=np.eye(4), intrinsic=np.eye(3, 4), img_width=1920, img_height=1200, distortion_coeffs=np.zeros(3) + ) + + # create a test case of projected lidar points in the image space + uv = np.array( + [ + [0, 0], + [camera_config.img_width - 0.3, 0], + [0, camera_config.img_height - 0.3], + [camera_config.img_width - 0.3, camera_config.img_height - 0.3], + ] + ) + uv_cam = np.ones((4, uv.shape[0])) + + # use the determine_valid_cam_coords() method + valid_pts_bool = determine_valid_cam_coords(uv, uv_cam, camera_config) + + # as done in draw_ground_pts_in_image() in ground_visualization.py + uv = np.round(uv[valid_pts_bool]).astype(np.int32) + + assert np.all(uv[:, 0] < camera_config.img_width) and np.all(uv[:, 1] < camera_config.img_height)