Beispiel #1
0
    def test_export(self):
        temp_kapture_dirpath = path.join(self._tempdir.name, 'kapture')
        shutil.copytree(self._kapture_dirpath, temp_kapture_dirpath)
        kapture_data = kapture.io.csv.kapture_from_dir(temp_kapture_dirpath)
        images_filepaths = images_to_filepaths(kapture_data.records_camera,
                                               temp_kapture_dirpath)
        # make sure there is no EXIF in images
        for image_filepath in images_filepaths.values():
            clear_exif(image_filepath)

        # insert gps to exif
        export_gps_to_exif(kapture_data=kapture_data,
                           kapture_dirpath=temp_kapture_dirpath)

        rebuilt_records = kapture.RecordsGnss()
        for timestamp, cam_id, image_name in kapture.flatten(
                kapture_data.records_camera):
            image_filepath = get_image_fullpath(temp_kapture_dirpath,
                                                image_name)
            exif_data = read_exif(image_filepath)
            rebuilt_records[timestamp, 'GPS_' +
                            cam_id] = convert_gps_to_kapture_record(exif_data)

        self.assertTrue(
            equal_records_gnss(kapture_data.records_gnss, rebuilt_records))
Beispiel #2
0
def extract_gps_from_exif(kapture_data: kapture.Kapture, kapture_dirpath: str):
    """
    Extract GPS coordinates from kapture dataset, returns the new sensor and gnss records.
    Gnss timestamps and sensor ids are guessed from timestamps and camera_id from images.
    The GNSS sensor_id are built prefixing 'GPS_'<cam_id>, with cam_id the sensor_id of the corresponding camera.

    :param kapture_data: input kapture data, must contains sensors and records_camera.
    :param kapture_dirpath: input path to kapture directory.
    :return:
    """
    # only load sensors + records_data:
    disable_tqdm = logger.getEffectiveLevel() != logging.INFO

    # make up new gps ids
    cam_to_gps_id = {  # cam_id -> gps_id
        cam_id: 'GPS_' + cam_id
        for cam_id, sensor in kapture_data.sensors.items()
        if sensor.sensor_type == 'camera'
    }  # cam_id -> gps_id

    # set all gps to EPSG:4326
    gps_epsg_codes = {gps_id: 'EPSG:4326' for gps_id in cam_to_gps_id.values()}
    # add new gps ids to sensors
    gnss_kapture_sensors = kapture.Sensors()
    for gps_id, epsg in gps_epsg_codes.items():
        gnss_kapture_sensors[gps_id] = kapture.Sensor(sensor_type='gnss',
                                                      sensor_params=[epsg])

    image_filepaths = images_to_filepaths(kapture_data.records_camera,
                                          kapture_dirpath=kapture_dirpath)
    records_gnss = kapture.RecordsGnss()

    for timestamp, cam_id, image_name in tqdm(kapture.flatten(
            kapture_data.records_camera),
                                              disable=disable_tqdm):
        image_filepath = image_filepaths[image_name]
        logger.debug(f'extracting GPS tags from {image_filepath}')
        gps_id = cam_to_gps_id[cam_id]
        exif_data = read_exif(image_filepath)
        gps_record = convert_gps_to_kapture_record(exif_data)
        records_gnss[timestamp, gps_id] = gps_record

    return gnss_kapture_sensors, records_gnss