twanghcmut's picture
download
raw
2.1 kB
import unittest
import numpy as np
from real2sim.reconstruction.plane import contact_table_height, plane_pointmap
class PlaneInitializationTests(unittest.TestCase):
def setUp(self):
self.camera = np.eye(4)
self.camera[:3, :3] = np.diag([1, -1, -1])
self.camera[:3, 3] = [0.2, 0.3, 1]
self.intrinsics = np.array([[100, 0, 2], [0, 100, 2], [0, 0, 1]])
self.mask = np.zeros((5, 5), dtype=bool)
self.mask[2, 2] = True
def test_plane_points_project_to_their_source_pixels(self):
points = plane_pointmap(
self.camera, self.intrinsics, (5, 5), 0.5, self.mask, 0.045
)
projected = points @ self.intrinsics.T
projected = projected[..., :2] / projected[..., 2:]
yy, xx = np.mgrid[:5, :5]
np.testing.assert_allclose(projected, np.stack((xx, yy), axis=-1), atol=1e-6)
world = points @ self.camera[:3, :3].T + self.camera[:3, 3]
np.testing.assert_allclose(world[..., 2], 0.5 + self.mask * 0.045, atol=1e-6)
def test_rays_behind_camera_are_invalid_instead_of_zero_depth(self):
camera = np.eye(4)
camera[2, 3] = 1
points = plane_pointmap(camera, self.intrinsics, (5, 5), 0.5, self.mask)
self.assertTrue(np.isnan(points).all())
def test_metric_table_prior_uses_contact_fingertips(self):
keypoints = np.zeros((6, 21, 3))
keypoints[:, :, 2] = 0.8
height = contact_table_height(
keypoints, 1, 5, object_height=0.045, finger_radius=0.005
)
self.assertAlmostEqual(height, 0.75)
with self.assertRaises(ValueError):
contact_table_height(keypoints, 5, 8)
def test_input_dimensions_and_nonfinite_calibration_are_rejected(self):
with self.assertRaises(ValueError):
plane_pointmap(self.camera, self.intrinsics, (6, 5), 0.5, self.mask)
with self.assertRaises(ValueError):
plane_pointmap(
self.camera, self.intrinsics, (5, 5), float("nan"), self.mask
)
if __name__ == "__main__":
unittest.main()

Xet Storage Details

Size:
2.1 kB
·
Xet hash:
062900f682d7c754232c93b150da5469b552ce0c505cc80cd7703d6a139e704a

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.