def test_stores_and_loads(self): kwargs = { 'matcher_nms_n': np.random.randint(0, 5), 'matcher_nms_tau': np.random.randint(0, 100), 'matcher_match_binsize': np.random.randint(0, 100), 'matcher_match_radius': np.random.randint(0, 500), 'matcher_match_disp_tolerance': np.random.randint(0, 10), 'matcher_outlier_disp_tolerance': np.random.randint(0, 10), 'matcher_outlier_flow_tolerance': np.random.randint(0, 10), 'matcher_multi_stage': np.random.choice([True, False]), 'matcher_half_resolution': np.random.choice([True, False]), 'matcher_refinement': np.random.choice(MatcherRefinement), 'bucketing_max_features': np.random.randint(0, 10), 'bucketing_bucket_width': np.random.randint(0, 100), 'bucketing_bucket_height': np.random.randint(0, 100), 'height': np.random.uniform(0.0, 3.0), 'pitch': np.random.uniform(0.0, 3.0), 'ransac_iters': np.random.randint(0, 100), 'inlier_threshold': np.random.uniform(0.0, 3.0), 'motion_threshold': np.random.uniform(0.0, 100.0) } obj = LibVisOMonoSystem(**kwargs) obj.save() # Load all the entities all_entities = list(VisionSystem.objects.all()) self.assertGreaterEqual(len(all_entities), 1) self.assertEqual(all_entities[0], obj) all_entities[0].delete()
def test_get_instance_returns_an_existing_instance_simple(self): obj = LibVisOMonoSystem() obj.save() result = LibVisOMonoSystem.get_instance() self.assertEqual(obj.pk, result.pk) self.assertEqual(obj, result)
def test_result_saves(self): # Make an image collection with some number of images images = [] image_builder = DemoImageBuilder(mode=ImageMode.MONOCULAR, width=160, height=120) num_images = 10 for time in range(num_images): image = image_builder.create_frame(time / num_images) image.save() images.append(image) image_collection = ImageCollection( images=images, timestamps=list(range(len(images))), sequence_type=ImageSequenceType.SEQUENTIAL ) image_collection.save() subject = LibVisOMonoSystem() subject.save() # Actually run the system using mocked images subject.set_camera_intrinsics(image_builder.get_camera_intrinsics(), 1 / 10) subject.start_trial(ImageSequenceType.SEQUENTIAL) for time, image in enumerate(images): subject.process_image(image, time) result = subject.finish_trial() self.assertIsInstance(result, SLAMTrialResult) self.assertEqual(len(image_collection), len(result.results)) result.image_source = image_collection result.save() # Load all the entities all_entities = list(SLAMTrialResult.objects.all()) self.assertGreaterEqual(len(all_entities), 1) self.assertEqual(all_entities[0], result) all_entities[0].delete() SLAMTrialResult._mongometa.collection.drop() ImageCollection._mongometa.collection.drop() Image._mongometa.collection.drop()
def test_get_instance_returns_an_existing_instance_complex(self): matcher_nms_n = np.random.randint(1, 5) matcher_nms_tau = np.random.randint(20, 100) matcher_match_binsize = np.random.randint(20, 100) matcher_match_radius = np.random.randint(20, 100) matcher_match_disp_tolerance = np.random.randint(1, 5) matcher_outlier_disp_tolerance = np.random.randint(2, 10) matcher_outlier_flow_tolerance = np.random.randint(2, 10) matcher_multi_stage = np.random.choice([True, False]) matcher_half_resolution = np.random.choice([True, False]) matcher_refinement = np.random.choice(MatcherRefinement) bucketing_max_features = np.random.randint(2, 10) bucketing_bucket_width = np.random.randint(20, 100) bucketing_bucket_height = np.random.randint(20, 100) height = np.random.uniform(0.8, 1.2) pitch = np.random.uniform(-0.1, 0.1) ransac_iters = np.random.randint(500, 3000) inlier_threshold = np.random.uniform(0, 0.0001) motion_threshold = np.random.uniform(20.0, 300.0) obj = LibVisOMonoSystem( matcher_nms_n=matcher_nms_n, matcher_nms_tau=matcher_nms_tau, matcher_match_binsize=matcher_match_binsize, matcher_match_radius=matcher_match_radius, matcher_match_disp_tolerance=matcher_match_disp_tolerance, matcher_outlier_disp_tolerance=matcher_outlier_disp_tolerance, matcher_outlier_flow_tolerance=matcher_outlier_flow_tolerance, matcher_multi_stage=matcher_multi_stage, matcher_half_resolution=matcher_half_resolution, matcher_refinement=matcher_refinement, bucketing_max_features=bucketing_max_features, bucketing_bucket_width=bucketing_bucket_width, bucketing_bucket_height=bucketing_bucket_height, height=height, pitch=pitch, ransac_iters=ransac_iters, inlier_threshold=inlier_threshold, motion_threshold=motion_threshold ) obj.save() result = LibVisOMonoSystem.get_instance( matcher_nms_n=matcher_nms_n, matcher_nms_tau=matcher_nms_tau, matcher_match_binsize=matcher_match_binsize, matcher_match_radius=matcher_match_radius, matcher_match_disp_tolerance=matcher_match_disp_tolerance, matcher_outlier_disp_tolerance=matcher_outlier_disp_tolerance, matcher_outlier_flow_tolerance=matcher_outlier_flow_tolerance, matcher_multi_stage=matcher_multi_stage, matcher_half_resolution=matcher_half_resolution, matcher_refinement=matcher_refinement, bucketing_max_features=bucketing_max_features, bucketing_bucket_width=bucketing_bucket_width, bucketing_bucket_height=bucketing_bucket_height, height=height, pitch=pitch, ransac_iters=ransac_iters, inlier_threshold=inlier_threshold, motion_threshold=motion_threshold ) self.assertEqual(obj.pk, result.pk) self.assertEqual(obj, result)