コード例 #1
0
ファイル: test_io_csv.py プロジェクト: ducha-aiki/kapture
    def test_trajectories_read(self):
        content = [
            '# timestamp, device_id, qw, qx, qy, qz, tx, ty, tz',
            '0, cam0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0',
            '    0, cam1, 0.5, 0.5, 0.5, 0.5, 4.0, 2.0, -2.0',
            '     100,  cam2,  1.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0'
        ]

        with open(self._temp_filepath, 'wt') as f:
            f.write(kapture_linesep.join(content))
        device_ids = {'cam0', 'cam1', 'cam2'}
        trajectories = csv.trajectories_from_file(self._temp_filepath,
                                                  device_ids)
        self.assertIsInstance(trajectories, kapture.Trajectories)
        self.assertEqual(2, len(trajectories.keys()))  # timestamps
        self.assertEqual(3,
                         len(trajectories.key_pairs()))  # timestamp x devices
        self.assertIn(0, trajectories)
        self.assertIn(100, trajectories)
        self.assertIn('cam0', trajectories[0])
        self.assertIn('cam1', trajectories[0])

        pose = kapture.PoseTransform(r=[0.5, 0.5, 0.5, 0.5], t=[4., 2., -2.])
        self.assertAlmostEqual(trajectories[(0, 'cam1')].r_raw, pose.r_raw)
        self.assertAlmostEqual(trajectories[(0, 'cam1')].t_raw, pose.t_raw)
コード例 #2
0
ファイル: test_io_csv.py プロジェクト: ducha-aiki/kapture
    def test_sensors_read(self):
        formatted_expected = kapture_linesep.join([
            '# sensor_id, name, sensor_type, [sensor_params]+',
            'cam0, cam0, camera, SIMPLE_PINHOLE, 640, 480, 100, 320, 240',
            'cam1, cam1, camera, SIMPLE_PINHOLE, 640, 480, 100, 320, 240', ''
        ])

        with open(self._temp_filepath, 'wt') as f:
            f.write(formatted_expected)

        sensors = csv.sensors_from_file(self._temp_filepath)
        self.assertIsInstance(sensors, kapture.Sensors)
        self.assertEqual(len(sensors), 2)
        self.assertIn('cam0', sensors)
        self.assertIn('cam1', sensors)
        self.assertEqual('cam0', sensors['cam0'].name)
        self.assertEqual('cam1', sensors['cam1'].name)
        self.assertEqual(kapture.SENSOR_TYPE_CAMERA,
                         sensors['cam0'].sensor_type)
        self.assertEqual(kapture.SENSOR_TYPE_CAMERA,
                         sensors['cam1'].sensor_type)
        self.assertEqual(6, len(sensors['cam1'].sensor_params))
        self.assertListEqual(
            sensors['cam0'].sensor_params,
            ['SIMPLE_PINHOLE', '640', '480', '100', '320', '240'])
コード例 #3
0
ファイル: test_io_csv.py プロジェクト: ducha-aiki/kapture
    def setUp(self):
        self._tempdir = tempfile.TemporaryDirectory()
        self._sensors_filepath = path.join(self._tempdir.name, 'sensors.txt')
        sensors_content = [
            '# sensor_id, name, sensor_type, [sensor_params]+',
            'gps1, gps_01, gnss, EPSG:4326',
            'gps2, gps_02, gnss, EPSG:4326',
        ]
        with open(self._sensors_filepath, 'wt') as f:
            f.write(kapture_linesep.join(sensors_content))

        self._gnss_filepath = path.join(self._tempdir.name, 'records_gnss.txt')
        gnss_content = [
            '# timestamp, device_id, x, y, z, utc, dop',
            '0, gps1, 28.099134, 49.38892, 8.0, 514850398, 3.0',
            '  1, gps1, 29.099134, 50.38892, 9.0, 514850399, 2.0',
            '  1, gps2, 29.099134, 50.38892, 9.0, 514850399, 2.0',
            '     2,   gps1, 30.099134, 51.38892, 10.0, 514850400, 1.0'
        ]
        with open(self._gnss_filepath, 'wt') as f:
            f.write(kapture_linesep.join(gnss_content))
コード例 #4
0
ファイル: test_io_csv.py プロジェクト: ducha-aiki/kapture
    def test_last_line_small_file(self):
        content = kapture_linesep.join([
            csv.KAPTURE_FORMAT_1,
            '# timestamp, device_id, qw, qx, qy, qz, tx, ty, tz',
            '0001, cam0,  1.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0',
            '0002, cam1,  0.5,  0.5,  0.5,  0.5,  4.0,  2.0, -2.0'
        ])
        last_line = '1000, cam2,  1.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0'
        with open(self._temp_filepath, 'wt') as fw:
            fw.write(content)
            fw.write(kapture_linesep + last_line)

        with open(self._temp_filepath, 'r') as fr:
            line = csv.get_last_line(fr)
        self.assertEqual(line, last_line)
コード例 #5
0
ファイル: test_io_csv.py プロジェクト: ducha-aiki/kapture
    def test_rig_write(self):
        rigs = kapture.Rigs()
        rigs['rig1', 'cam0'] = kapture.PoseTransform()
        rigs['rig1', 'cam1'] = kapture.PoseTransform(r=[0.5, 0.5, 0.5, 0.5])
        content_expected = kapture_linesep.join([
            csv.KAPTURE_FORMAT_1,
            '# rig_id, sensor_id, qw, qx, qy, qz, tx, ty, tz',
            'rig1, cam0,  1.0,  0.0,  0.0,  0.0,  0.0,  0.0,  0.0',
            'rig1, cam1,  0.5,  0.5,  0.5,  0.5,  0.0,  0.0,  0.0', ''
        ])

        csv.rigs_to_file(self._temp_filepath, rigs)
        with open(self._temp_filepath, 'rt') as f:
            content_actual = ''.join(f.readlines())
        self.assertEqual(content_expected, content_actual)
コード例 #6
0
ファイル: test_io_csv.py プロジェクト: ducha-aiki/kapture
    def test_sensors_write(self):
        cam0 = kapture.Camera(name='cam0',
                              camera_type='SIMPLE_PINHOLE',
                              camera_params=[640, 480, 100, 320, 240])
        cam1 = kapture.Camera(name='cam1',
                              camera_type='SIMPLE_PINHOLE',
                              camera_params=[640, 480, 100, 320, 240])
        formatted_expected = kapture_linesep.join([
            csv.KAPTURE_FORMAT_1,
            '# sensor_id, name, sensor_type, [sensor_params]+',
            'cam0, cam0, camera, SIMPLE_PINHOLE, 640, 480, 100, 320, 240',
            'cam1, cam1, camera, SIMPLE_PINHOLE, 640, 480, 100, 320, 240', ''
        ])
        sensors = kapture.Sensors()
        sensors['cam0'] = cam0
        sensors['cam1'] = cam1
        csv.sensors_to_file(self._temp_filepath, sensors)
        with open(self._temp_filepath, 'rt') as f:
            formatted_actual = ''.join(f.readlines())

        self.assertEqual(formatted_actual, formatted_expected)
コード例 #7
0
ファイル: test_io_csv.py プロジェクト: ducha-aiki/kapture
 def setUp(self):
     self._tempdir = tempfile.TemporaryDirectory()
     self._observations_expected_filepath = path.join(
         self._tempdir.name, 'expected', 'observations.txt')
     self._observations_actual_filepath = path.join(self._tempdir.name,
                                                    'actual',
                                                    'observations.txt')
     # creates ground truth couple data/file
     self._observations_expected = kapture.Observations({
         0: [('image1.jpg', 0), ('image2.jpg', 0)],
         2: [('image1.jpg', 2), ('image2.jpg', 3)]
     })
     self._observations_csv_expected = csv.KAPTURE_FORMAT_1 + kapture_linesep
     self._observations_csv_expected += kapture_linesep.join([
         "# point3d_id, [image_path, feature_id]*",
         "0, image1.jpg, 0, image2.jpg, 0",
         "2, image1.jpg, 2, image2.jpg, 3"
     ]) + kapture_linesep
     os.makedirs(path.dirname(self._observations_expected_filepath),
                 exist_ok=True)
     with open(self._observations_expected_filepath, 'wt') as file:
         file.write(self._observations_csv_expected)