Пример #1
0
def get_geotag_properties_from_exif(image, offset_angle=0.0, verbose=False):
    try:
        exif = ExifRead(image)
    except:
        print(
            "Error, EXIF could not be read for image " + image +
            ", geotagging process failed for this image since gps/time properties not read."
        )
        return None
    # required tags
    try:
        lon, lat = exif.extract_lon_lat()
    except:
        print(
            "Error, " + image +
            " image latitude or longitude tag not in EXIF. Geotagging process failed for this image, since this is required information."
        )
        return None
    if lat != None and lon != None:
        geotag_properties = {"MAPLatitude": lat}
        geotag_properties["MAPLongitude"] = lon
    else:
        print(
            "Error, " + image +
            " image latitude or longitude tag not in EXIF. Geotagging process failed for this image, since this is required information."
        )
        return None
    try:
        timestamp = exif.extract_capture_time()
    except:
        print(
            "Error, " + image +
            " image capture time tag not in EXIF. Geotagging process failed for this image, since this is required information."
        )
        return None

    geotag_properties["MAPCaptureTime"] = datetime.datetime.strftime(
        timestamp, "%Y_%m_%d_%H_%M_%S_%f")[:-3]

    # optional fields
    try:
        geotag_properties["MAPAltitude"] = exif.extract_altitude()
    except:
        if verbose:
            print("Warning, image altitude tag not in EXIF.")
    try:
        heading = exif.extract_direction()
        if heading is None:
            heading = 0.0
        heading = normalize_bearing(heading + offset_angle)
        # bearing of the image
        geotag_properties["MAPCompassHeading"] = {
            "TrueHeading": heading,
            "MagneticHeading": heading
        }
    except:
        if verbose:
            print("Warning, image direction tag not in EXIF.")

    return geotag_properties
Пример #2
0
def get_geotag_properties_from_exif(image, offset_angle=0.0, verbose=False):
    try:
        exif = ExifRead(image)
    except:
        print_error("Error, EXIF could not be read for image " +
                    image + ", geotagging process failed for this image since gps/time properties not read.")
        return None
    # required tags
    try:
        lon, lat = exif.extract_lon_lat()
    except:
        print_error("Error, " + image +
                    " image latitude or longitude tag not in EXIF. Geotagging process failed for this image, since this is required information.")
        return None
    if lat != None and lon != None:
        geotag_properties = {"MAPLatitude": lat}
        geotag_properties["MAPLongitude"] = lon
    else:
        print_error("Error, " + image +
                    " image latitude or longitude tag not in EXIF. Geotagging process failed for this image, since this is required information.")
        return None
    try:
        timestamp = exif.extract_capture_time()
    except:
        print_error("Error, " + image +
                    " image capture time tag not in EXIF. Geotagging process failed for this image, since this is required information.")
        return None

    try:
        geotag_properties["MAPCaptureTime"] = datetime.datetime.strftime(
            timestamp, "%Y_%m_%d_%H_%M_%S_%f")[:-3]
    except:
        print_error("Error, {} image capture time tag incorrect format. Geotagging process failed for this image, since this is required information.".format(image))
        return None

    # optional fields
    try:
        geotag_properties["MAPAltitude"] = exif.extract_altitude()
    except:
        if verbose:
            print("Warning, image altitude tag not in EXIF.")
    try:
        heading = exif.extract_direction()
        if heading is None:
            heading = 0.0
        heading = normalize_bearing(heading + offset_angle)
        # bearing of the image
        geotag_properties["MAPCompassHeading"] = {"TrueHeading": heading,
                                                  "MagneticHeading": heading}
    except:
        if verbose:
            print("Warning, image direction tag not in EXIF.")

    return geotag_properties
Пример #3
0
    def extract_direction(self):
        '''
        Extract image direction (i.e. compass, heading, bearing)
        '''
        fields = ['GPS GPSImgDirection',
                  'EXIF GPS GPSImgDirection',
                  'GPS GPSTrack',
                  'EXIF GPS GPSTrack']
        direction, _ = self._extract_alternative_fields(fields)

        if direction is not None:
            direction = normalize_bearing(direction, check_hex=True)
        return direction
Пример #4
0
    def extract_direction(self):
        '''
        Extract image direction (i.e. compass, heading, bearing)
        '''
        fields = ['GPS GPSImgDirection',
                  'EXIF GPS GPSImgDirection',
                  'GPS GPSTrack',
                  'EXIF GPS GPSTrack']
        direction, _ = self._extract_alternative_fields(fields)

        if direction is not None:
            direction = normalize_bearing(direction, check_hex=True)
        return direction