def test_import(self): bundler_file_path = path.join(self.aachen_models_folder, 'aachen_cvpr2018_db.out') bundler_imagelist_path = path.join(self.aachen_models_folder, 'aachen_cvpr2018_db.list.txt') with tempfile.TemporaryDirectory() as tmpdirname: import_bundler(bundler_file_path, bundler_imagelist_path, self.images_folder, tmpdirname, ignore_trajectories=False, add_reconstruction=True, force_overwrite_existing=True) expected_kdata = kapture_from_dir( path.join(self.aachen_folder, 'kapture/training')) expected_kdata.sensors = self.bundler_sensors imported_aachen_data = kapture_from_dir(tmpdirname) self.assertTrue(equal_kapture(imported_aachen_data, expected_kdata)) # test without trajectories with tempfile.TemporaryDirectory() as tmpdirname: import_bundler(bundler_file_path, bundler_imagelist_path, self.images_folder, tmpdirname, ignore_trajectories=True, add_reconstruction=True, force_overwrite_existing=True) expected_kdata = kapture_from_dir( path.join(self.aachen_folder, 'kapture/training')) expected_kdata.sensors = self.bundler_sensors expected_kdata._trajectories = None imported_aachen_data = kapture_from_dir(tmpdirname) self.assertTrue(equal_kapture(imported_aachen_data, expected_kdata)) # test without points3d with tempfile.TemporaryDirectory() as tmpdirname: import_bundler(bundler_file_path, bundler_imagelist_path, self.images_folder, tmpdirname, ignore_trajectories=False, add_reconstruction=False, force_overwrite_existing=True) expected_kdata = kapture_from_dir( path.join(self.aachen_folder, 'kapture/training')) expected_kdata.sensors = self.bundler_sensors expected_kdata._points3d = None expected_kdata._keypoints = None expected_kdata._observations = None imported_aachen_data = kapture_from_dir(tmpdirname) self.assertTrue(equal_kapture(imported_aachen_data, expected_kdata))
def test_import_two_models(self): nvm_path = path.join(self.aachen_models_folder, 'aachen_two_parts.nvm') with tempfile.TemporaryDirectory() as tmpdirname: import_nvm(nvm_path, self.images_folder, tmpdirname, filter_list_path="", ignore_trajectories=False, add_reconstruction=True, force_overwrite_existing=True) expected_kdata = kapture_from_dir(path.join(self.aachen_folder, 'kapture/training')) imported_aachen_data = kapture_from_dir(tmpdirname) self.assertTrue(equal_kapture(imported_aachen_data, expected_kdata)) # test without trajectories with tempfile.TemporaryDirectory() as tmpdirname: import_nvm(nvm_path, self.images_folder, tmpdirname, filter_list_path="", ignore_trajectories=True, add_reconstruction=True, force_overwrite_existing=True) expected_kdata = kapture_from_dir(path.join(self.aachen_folder, 'kapture/training')) expected_kdata._trajectories = None imported_aachen_data = kapture_from_dir(tmpdirname) self.assertTrue(equal_kapture(imported_aachen_data, expected_kdata)) # test without points3d with tempfile.TemporaryDirectory() as tmpdirname: import_nvm(nvm_path, self.images_folder, tmpdirname, filter_list_path="", ignore_trajectories=False, add_reconstruction=False, force_overwrite_existing=True) expected_kdata = kapture_from_dir(path.join(self.aachen_folder, 'kapture/training')) expected_kdata._points3d = None expected_kdata._keypoints = None expected_kdata._observations = None imported_aachen_data = kapture_from_dir(tmpdirname) self.assertTrue(equal_kapture(imported_aachen_data, expected_kdata)) # test with filter list with tempfile.TemporaryDirectory() as tmpdirname: import_nvm(nvm_path, self.images_folder, tmpdirname, filter_list_path=self.filter, ignore_trajectories=True, add_reconstruction=False, force_overwrite_existing=True) imported_aachen_data = kapture_from_dir(tmpdirname) self.assertTrue(len(imported_aachen_data.records_camera.key_pairs()) == 2) images_set = {image_path for _, _, image_path in kapture.flatten(imported_aachen_data.records_camera)} self.assertTrue('db/1045.jpg' in images_set) self.assertFalse('db/4446.jpg' in images_set) self.assertTrue('db/1135.jpg' in images_set) self.assertIsNone(imported_aachen_data.trajectories) self.assertIsNone(imported_aachen_data.points3d)
def test_import_t265_rosbag(self): # rosbag was trimmed with # filter LocOffice_2019-03-21-15-57-04.bag trimmed_bag.bag "t.secs <= 1553180224 and t.nsecs <= 460916281" self.importer.import_multi_camera(odometry_topic=TOPIC_ODOMETRY, image_topics=[ '/camera/fisheye1/image_raw', '/camera/fisheye2/image_raw' ], camera_identifiers=self.camera_ids, save_all_positions=False, find_image_position=True) rig_id = list(self.importer._rigs.keys())[0] self.importer.save_to_kapture(rig_id) rosbag_kapture_data = kcsv.kapture_from_dir( self.ros_sample_kapture_path) imported_data = kcsv.kapture_from_dir(self.kapture_path) self.assertEqual(len(imported_data.trajectories), len(rosbag_kapture_data.records_camera), "one pose per image pair") self.assertTrue(equal_kapture(rosbag_kapture_data, imported_data), "Imported kapture ok") images_path = kapture.io.records.get_image_fullpath(self.kapture_path) images_files = [] for root, dirs, files in os.walk(images_path): for name in files: images_files.append(path.join(root, name)) self.assertEqual(len(images_files), 6) # Check the files exist for image_file in images_files: self.assertTrue(path.isfile(image_file), f"Image file {image_file} exist")
def test_import(self): expected_kdata = kapture_from_dir(self.kapture_gt_folder) with tempfile.TemporaryDirectory() as tmpdirname: import_7scenes(d7scenes_path=self.d7s_gt_folder, kapture_dir_path=tmpdirname, force_overwrite_existing=True) imported_kdata = kapture_from_dir(tmpdirname) self.assertTrue(equal_kapture(imported_kdata, expected_kdata))
def test_import_sequence(self): kapture_gt_dirpath = path.join(self.kapture_gt_rootpath, 'seq-01') import_7scenes(d7scenes_path=self.d7scenes_rootpath + '/seq-01', kapture_dir_path=self._tempdir.name, force_overwrite_existing=True) imported_kdata = kapture_from_dir(self._tempdir.name) expected_kdata = kapture_from_dir(kapture_gt_dirpath) self.assertTrue(equal_kapture(imported_kdata, expected_kdata))
def test_import_with_intrinsics(self): with tempfile.TemporaryDirectory() as tmpdirname: queries_with_intrinsics_path = path.join(self.query_folder, 'day_time_queries_with_intrinsics.txt') import_image_list([queries_with_intrinsics_path], self.images_folder, tmpdirname, force_overwrite_existing=True) expected_kdata = kapture_from_dir(self.kapture_query_path) imported_aachen_data = kapture_from_dir(tmpdirname) self.assertTrue(equal_kapture(imported_aachen_data, expected_kdata))
def test_import_query(self): kapture_gt_dirpath = path.join(self.kapture_gt_rootpath, 'query') import_7scenes(d7scenes_path=self.d7scenes_rootpath, kapture_dir_path=self._tempdir.name, force_overwrite_existing=True, partition='query') imported_kdata = kapture_from_dir(self._tempdir.name) expected_kdata = kapture_from_dir(kapture_gt_dirpath) self.assertTrue(equal_kapture(imported_kdata, expected_kdata))
def test_import_both(self): kapture_gt_dirpath = path.join(self.kapture_gt_rootpath, 'both') import_7scenes(d7scenes_path=self.d7scenes_rootpath, kapture_dir_path=self._tempdir.name, force_overwrite_existing=True, images_import_method=TransferAction.copy) imported_kdata = kapture_from_dir(self._tempdir.name) expected_kdata = kapture_from_dir(kapture_gt_dirpath) self.assertTrue(equal_kapture(imported_kdata, expected_kdata))
def test_import(self): temp_kapture_dirpath = path.join(self._tempdir.name, 'kapture') shutil.copytree(self._kapture_dirpath, temp_kapture_dirpath) # remove all GPS data temp_kapture_data = kapture.io.csv.kapture_from_dir(temp_kapture_dirpath) temp_kapture_data.records_gnss = None for gps_id in [k for k in temp_kapture_data.sensors.keys() if k.startswith('GPS_')]: del temp_kapture_data.sensors[gps_id] kapture.io.csv.kapture_to_dir(temp_kapture_dirpath, temp_kapture_data) # do the import import_gps_from_exif(temp_kapture_dirpath) # reload temp_kapture_data = kapture.io.csv.kapture_from_dir(temp_kapture_dirpath) self.assertTrue(equal_kapture(temp_kapture_data, self._kapture_data))
def test_import_without_intrinsics(self): with tempfile.TemporaryDirectory() as tmpdirname: queries_without_intrinsics_path = path.join(self.query_folder, 'day_time_queries_without_intrinsics.txt') import_image_list([queries_without_intrinsics_path], self.images_folder, tmpdirname, force_overwrite_existing=True) expected_kdata = kapture_from_dir(self.kapture_query_path) # set all sensors to unknown for sensor_id in expected_kdata.sensors.keys(): sensor = expected_kdata.sensors[sensor_id] assert isinstance(sensor, kapture.Camera) expected_kdata.sensors[sensor_id] = kapture.Camera(kapture.CameraType.UNKNOWN_CAMERA, sensor.camera_params[0:2]) imported_aachen_data = kapture_from_dir(tmpdirname) self.assertTrue(equal_kapture(imported_aachen_data, expected_kdata))
def test_import_opensfm(self) -> None: """ Test the import_opensfm function on small sample """ # convert and then load file_operation = TransferAction.skip if self.isWindows else TransferAction.link_relative import_opensfm( self._opensfm_sample_path, self._kapture_rebuilt_path, force_overwrite_existing=False, images_import_method=file_operation ) kapture_data_expected = csv.kapture_from_dir(self._kapture_sample_path) kapture_data_actual = csv.kapture_from_dir(self._kapture_rebuilt_path) # check in detail what could be wrong self.assertTrue(equal_sensors(kapture_data_expected.sensors, kapture_data_actual.sensors)) self.assertTrue(equal_records_gnss(kapture_data_expected.records_gnss, kapture_data_actual.records_gnss)) # check all at once self.assertTrue(equal_kapture(kapture_data_expected, kapture_data_actual))
def test_utbm_images_rosbag_import(self) -> None: """ Test the import of an image rosbag """ # Use a small bb2 rosbag rosbag_path = path.join(self._samples_utbm_folder, '2018-07-13-15-17-20_1_first10_bb2.bag') sensors = import_utbm_sensors([ path.join(self._samples_utbm_folder, 'bb2_left.yaml'), path.join(self._samples_utbm_folder, 'bb2_right.yaml') ]) importer = RosBagImporter(rosbag_path, None, sensors, self.kapture_path, force_overwrite_existing=True) importer.import_multi_camera(None, TOPICS_BB2, BB2_CAMERA_IDENTIFIERS, False, False) importer.save_to_kapture() ros_sample_kapture_path = path.join( self._samples_utbm_folder, '2018-07-13-15-17-20_1_first10_bb2_kapture') rosbag_kapture_data = kcsv.kapture_from_dir(ros_sample_kapture_path) imported_data = kcsv.kapture_from_dir(self.kapture_path) self.assertTrue(equal_kapture(rosbag_kapture_data, imported_data), "Imported UTBM kapture ok") images_path = kapture.io.records.get_image_fullpath(self.kapture_path) images_files = [] for root, dirs, files in os.walk(images_path): for name in files: images_files.append(path.join(root, name)) self.assertEqual(len(images_files), 10) # Check the files exist for image_file in images_files: self.assertTrue(path.isfile(image_file), f"Image file {image_file} exist")
def test_import(self): image_transfer_action = TransferAction.skip with tempfile.TemporaryDirectory() as tmpdirname: configuration = 'all' light_range = [1, 4] loop_range = [1] camera_range = list(range(0, 6)) occlusion_range = [2, 3] as_rig = False import_virtual_gallery(self.virtual_gallery_1_0_0_folder, configuration, light_range, loop_range, camera_range, occlusion_range, as_rig, image_transfer_action, tmpdirname, force_overwrite_existing=True) expected_kdata = kapture_from_dir(path.join(self.virtual_gallery_folder, 'kapture/all')) imported_virtual_gallery_data = kapture_from_dir(tmpdirname) self.assertTrue(equal_kapture(imported_virtual_gallery_data, expected_kdata)) with tempfile.TemporaryDirectory() as tmpdirname: configuration = 'all' light_range = [4] loop_range = [1] camera_range = [2] occlusion_range = [3] as_rig = False import_virtual_gallery(self.virtual_gallery_1_0_0_folder, configuration, light_range, loop_range, camera_range, occlusion_range, as_rig, image_transfer_action, tmpdirname, force_overwrite_existing=True) expected_kdata = kapture_from_dir(path.join(self.virtual_gallery_folder, 'kapture/reduced')) imported_virtual_gallery_data = kapture_from_dir(tmpdirname) self.assertTrue(equal_kapture(imported_virtual_gallery_data, expected_kdata)) with tempfile.TemporaryDirectory() as tmpdirname: configuration = 'training' light_range = [1, 4] loop_range = [1] camera_range = list(range(0, 6)) occlusion_range = [2, 3] as_rig = False import_virtual_gallery(self.virtual_gallery_1_0_0_folder, configuration, light_range, loop_range, camera_range, occlusion_range, as_rig, image_transfer_action, tmpdirname, force_overwrite_existing=True) expected_kdata = kapture_from_dir(path.join(self.virtual_gallery_folder, 'kapture/training')) imported_virtual_gallery_data = kapture_from_dir(tmpdirname) self.assertTrue(equal_kapture(imported_virtual_gallery_data, expected_kdata)) with tempfile.TemporaryDirectory() as tmpdirname: configuration = 'training' light_range = [1, 4] loop_range = [1] camera_range = list(range(0, 6)) occlusion_range = [2, 3] as_rig = True import_virtual_gallery(self.virtual_gallery_1_0_0_folder, configuration, light_range, loop_range, camera_range, occlusion_range, as_rig, image_transfer_action, tmpdirname, force_overwrite_existing=True) expected_kdata = kapture_from_dir(path.join(self.virtual_gallery_folder, 'kapture/training')) imported_virtual_gallery_data = kapture_from_dir(tmpdirname) self.assertFalse(equal_kapture(imported_virtual_gallery_data, expected_kdata)) rigs_remove_inplace(imported_virtual_gallery_data.trajectories, imported_virtual_gallery_data.rigs) self.assertTrue(equal_kapture(imported_virtual_gallery_data, expected_kdata)) with tempfile.TemporaryDirectory() as tmpdirname: configuration = 'testing' light_range = [1, 4] loop_range = [1] camera_range = list(range(0, 6)) occlusion_range = [2, 3] as_rig = False import_virtual_gallery(self.virtual_gallery_1_0_0_folder, configuration, light_range, loop_range, camera_range, occlusion_range, as_rig, image_transfer_action, tmpdirname, force_overwrite_existing=True) expected_kdata = kapture_from_dir(path.join(self.virtual_gallery_folder, 'kapture/testing')) imported_virtual_gallery_data = kapture_from_dir(tmpdirname) self.assertTrue(equal_kapture(imported_virtual_gallery_data, expected_kdata))
def test_copy_equal(self): kapture_data_copy = copy.deepcopy(self._kapture_data) self.assertTrue(equal_kapture(kapture_data_copy, self._kapture_data))