π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
added some tests
Luis Ferraz761850d6b639
diff --git a/test/geometry/calibration/test_distort.py b/test/geometry/calibration/test_distort.pyindex 9ea116dbf..76f838e98 100644--- a/test/geometry/calibration/test_distort.py+++ b/test/geometry/calibration/test_distort.py@@ -14,6 +14,10 @@ class TestDistortPoints:pointsu = distort_points(points, K, distCoeff)assert points.shape == pointsu.shape+ new_K = torch.rand(3, 3, device=device, dtype=dtype)+ pointsu = distort_points(points, K, distCoeff, new_K)+ assert points.shape == pointsu.shape+def test_smoke_batch(self, device, dtype):points = torch.rand(1, 1, 2, device=device, dtype=dtype)K = torch.rand(1, 3, 3, device=device, dtype=dtype)@@ -21,6 +25,10 @@ class TestDistortPoints:pointsu = distort_points(points, K, distCoeff)assert points.shape == pointsu.shape+ new_K = torch.rand(1, 3, 3, device=device, dtype=dtype)+ pointsu = distort_points(points, K, distCoeff, new_K)+ assert points.shape == pointsu.shape+@pytest.mark.parametrize("batch_size, num_points, num_distcoeff", [(1, 3, 4), (2, 4, 5), (3, 5, 8), (4, 6, 12), (5, 7, 14)])@@ -29,23 +37,26 @@ class TestDistortPoints:points = torch.rand(B, N, 2, device=device, dtype=dtype)K = torch.rand(B, 3, 3, device=device, dtype=dtype)+ new_K = torch.rand(B, 3, 3, device=device, dtype=dtype)distCoeff = torch.rand(B, Ndist, device=device, dtype=dtype)- pointsu = distort_points(points, K, distCoeff)+ pointsu = distort_points(points, K, distCoeff, new_K)assert pointsu.shape == (B, N, 2)def test_gradcheck(self, device):points = torch.rand(1, 8, 2, device=device, dtype=torch.float64, requires_grad=True)K = torch.rand(1, 3, 3, device=device, dtype=torch.float64)+ new_K = torch.rand(1, 3, 3, device=device, dtype=torch.float64)distCoeff = torch.rand(1, 4, device=device, dtype=torch.float64)- assert gradcheck(distort_points, (points, K, distCoeff), raise_exception=True)+ assert gradcheck(distort_points, (points, K, distCoeff, new_K), raise_exception=True)def test_jit(self, device, dtype):points = torch.rand(1, 1, 2, device=device, dtype=dtype)K = torch.rand(1, 3, 3, device=device, dtype=dtype)+ new_K = torch.rand(1, 3, 3, device=device, dtype=dtype)distCoeff = torch.rand(1, 4, device=device, dtype=dtype)- inputs = (points, K, distCoeff)+ inputs = (points, K, distCoeff, new_K)op = distort_pointsop_jit = torch.jit.script(op)diff --git a/test/geometry/calibration/test_undistort.py b/test/geometry/calibration/test_undistort.pyindex 849882c05..74c8dd38b 100644--- a/test/geometry/calibration/test_undistort.py+++ b/test/geometry/calibration/test_undistort.py@@ -14,12 +14,21 @@ class TestUndistortPoints:pointsu = undistort_points(points, K, distCoeff)assert points.shape == pointsu.shape+ new_K = torch.rand(3, 3, device=device, dtype=dtype)+ pointsu = undistort_points(points, K, distCoeff, new_K)+ assert points.shape == pointsu.shape++ def test_smoke_batch(self, device, dtype):points = torch.rand(1, 1, 2, device=device, dtype=dtype)K = torch.rand(1, 3, 3, device=device, dtype=dtype)distCoeff = torch.rand(1, 4, device=device, dtype=dtype)pointsu = undistort_points(points, K, distCoeff)assert points.shape == pointsu.shape+ new_K = torch.rand(1, 3, 3, device=device, dtype=dtype)+ pointsu = undistort_points(points, K, distCoeff, new_K)+ assert points.shape == pointsu.shape+@pytest.mark.parametrize("batch_size, num_points, num_distcoeff", [(1, 3, 4), (2, 4, 5), (3, 5, 8), (4, 6, 12), (5, 7, 14)])@@ -33,6 +42,10 @@ class TestUndistortPoints:pointsu = undistort_points(points, K, distCoeff)assert pointsu.shape == (B, N, 2)+ new_K = torch.rand(B, 3, 3, device=device, dtype=dtype)+ pointsu = undistort_points(points, K, distCoeff, new_K)+ assert pointsu.shape == (B, N, 2)+def test_opencv_five_coeff(self, device, dtype):# Test using 5 distortion coefficientspts = torch.tensor(@@ -57,6 +70,20 @@ class TestUndistortPoints:ptsu = undistort_points(pts, K, dist)assert_close(ptsu, ptsu_expected, rtol=1e-4, atol=1e-4)+ new_K = K * 2+ new_K[2, 2] = 1+ # Expected output generated with OpenCV:+ # import cv2+ # ptsu_expected = cv2.undistortPoints(pts.numpy().reshape(-1,1,2), K.numpy(),+ # dist.numpy(), None, None, new_K.numpy()).reshape(-1,2)+ print(ptsu_expected)+ ptsu_expected = 2 * torch.tensor(+ [[1030.5992, 790.65533], [1027.3059, 718.10020], [1024.0700, 645.90600]], device=device, dtype=dtype+ )+ print(ptsu_expected)+ ptsu = undistort_points(pts, K, dist, new_K)+ assert_close(ptsu, ptsu_expected, rtol=1e-4, atol=1e-4)+def test_opencv_all_coeff(self, device, dtype):# Test using 14 distortion coefficientspts = torch.tensor(@@ -100,6 +127,20 @@ class TestUndistortPoints:ptsu = undistort_points(pts, K, dist)assert_close(ptsu, ptsu_expected, rtol=1e-4, atol=1e-4)+ new_K = K * 2+ new_K[2, 2] = 1+ # Expected output generated with OpenCV:+ # import cv2+ # ptsu_expected = cv2.undistortPoints(pts.numpy().reshape(-1,1,2), K.numpy(),+ # dist.numpy(), None, None, new_K.numpy()).reshape(-1,2)+ print(ptsu_expected)+ ptsu_expected = 2 * torch.tensor(+ [[1030.8245, 786.3807], [1027.5505, 715.0732], [1024.2753, 644.0319]], device=device, dtype=dtype+ )+ print(ptsu_expected)+ ptsu = undistort_points(pts, K, dist, new_K)+ assert_close(ptsu, ptsu_expected, rtol=1e-4, atol=1e-4)+def test_opencv_stereo(self, device, dtype):# Udistort stereo points with data given in two batches using 14 distortion coefficientspts = torch.tensor(@@ -188,15 +229,17 @@ class TestUndistortPoints:def test_gradcheck(self, device):points = torch.rand(1, 8, 2, device=device, dtype=torch.float64, requires_grad=True)K = torch.rand(1, 3, 3, device=device, dtype=torch.float64)+ new_K = torch.rand(1, 3, 3, device=device, dtype=torch.float64)distCoeff = torch.rand(1, 4, device=device, dtype=torch.float64)- assert gradcheck(undistort_points, (points, K, distCoeff), raise_exception=True)+ assert gradcheck(undistort_points, (points, K, distCoeff, new_K), raise_exception=True)def test_jit(self, device, dtype):points = torch.rand(1, 1, 2, device=device, dtype=dtype)K = torch.rand(1, 3, 3, device=device, dtype=dtype)+ new_K = torch.rand(1, 3, 3, device=device, dtype=dtype)distCoeff = torch.rand(1, 4, device=device, dtype=dtype)- inputs = (points, K, distCoeff)+ inputs = (points, K, distCoeff, new_K)op = undistort_pointsop_jit = torch.jit.script(op)