Datasets:
Download code/robohome/src/engine/tests/test_pitched_target_cameras.py from RoboParty/RoboHome: direct link, hf CLI and curl.
- Browser
- Download file 3.3 kB
-
https://huggingface.co/datasets/RoboParty/RoboHome/resolve/main/code/robohome/src/engine/tests/test_pitched_target_cameras.py
- Command line
-
hf download hf://datasets/RoboParty/RoboHome/code/robohome/src/engine/tests/test_pitched_target_cameras.py
-
curl -L -o test_pitched_target_cameras.py https://huggingface.co/datasets/RoboParty/RoboHome/resolve/main/code/robohome/src/engine/tests/test_pitched_target_cameras.py
3.3 kB
| """Target cameras rank the view they render, including upward/downward pitch.""" | |
| import math | |
| from pathlib import Path | |
| import sys | |
| import unittest | |
| sys.path.insert(0, str(Path(__file__).resolve().parents[1])) | |
| import visibility_plan as visibility | |
| class PitchedTargetCameraTests(unittest.TestCase): | |
| def test_clear_low_plant_view_beats_distant_view_through_sofa(self): | |
| # Reduced geometry from a saved scene whose two old target cameras | |
| # were completely occluded by the sofa (512/512 sampled mesh rays). | |
| room = [[5.63, 6.29, 0.], [10.42, 10.59, 3.]] | |
| entities = [dict(entity_id='plant', room_id='living', role='plant', | |
| world_bbox_m=[[6.335, 9.168, 0.], [6.500, 9.359, .327]]), | |
| dict(entity_id='sofa', room_id='living', role='sofa', | |
| world_bbox_m=[[6.535, 8.171, 0.], [9.122, 9.885, 1.0285]])] | |
| cameras = [c for c in visibility._target_cameras('living', room, entities, 1280, 720) | |
| if c['target_ids'] == ['plant']] | |
| self.assertEqual(len(cameras), 2) | |
| # The safe western aisle gives a direct line to the plant; the sofa | |
| # occupies the east side. This is a selection assertion, not proof | |
| # of rendered visibility. | |
| for camera in cameras: | |
| with self.subTest(camera=camera['camera_id']): | |
| self.assertLess(camera['location'][0], 6.535) | |
| self.assertEqual(camera['target'], [6.4175, 9.2635, .1635]) | |
| self.assertEqual(camera['location'][2], 1.55) | |
| self.assertFalse(camera['required']) | |
| self.assertGreaterEqual(math.dist(cameras[0]['location'], cameras[1]['location']), .5) | |
| def test_pitched_view_fits_small_target_above_and_below_eye(self): | |
| room = [[0., 0., 0.], [10., 10., 4.]] | |
| location = [4., 2., 1.55] | |
| for height in (.2, 2.9): | |
| for aspect in (720/1280, 1280/720): | |
| with self.subTest(height=height, aspect=aspect): | |
| target = [4., 3.5, height] | |
| entity = dict(entity_id='target') | |
| bounds = [[3.95, 3.45, height-.05], [4.05, 3.55, height+.05]] | |
| # The 10 cm target is centered by the optical axis and | |
| # all eight corners fit comfortably at either pitch. | |
| # No room wall or other entity adds a foreground penalty. | |
| score = visibility._composition_score(location, target, room, | |
| [(entity, bounds)], [(entity, bounds)], 24., 0., aspect) | |
| self.assertAlmostEqual(score, 8*2+.15*1.5, places=8) | |
| def test_zero_pitch_preserves_level_projection_score(self): | |
| room = [[0., 0., 0.], [10., 10., 4.]] | |
| entity = dict(entity_id='target') | |
| bounds = [[2., 3., .1], [3., 4., 2.]] | |
| for shift in (0., -.08, -.27): | |
| with self.subTest(shift=shift): | |
| args = (room, [(entity, bounds)], [(entity, bounds)], 24., shift, 720/1280) | |
| flat = visibility._composition_score([4., 2., 1.55], [2.5, 3.5], *args) | |
| pitched = visibility._composition_score([4., 2., 1.55], [2.5, 3.5, 1.55], *args) | |
| self.assertEqual(flat, pitched) | |
| if __name__ == '__main__': | |
| unittest.main() | |