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
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
def get_images_geotags(process_file_list): geotags = [] missing_geotags = [] for image in sorted(process_file_list): exif = ExifRead(image) timestamp = exif.extract_capture_time() lon, lat = exif.extract_lon_lat() altitude = exif.extract_altitude() if timestamp and lon and lat: geotags.append((timestamp, lat, lon, altitude)) continue if timestamp and (not lon or not lat): missing_geotags.append((image, timestamp)) else: print("Error image {} does not have captured time.".format(image)) return geotags, missing_geotags
def get_images_geotags(process_file_list): geotags = [] missing_geotags = [] for image in tqdm(sorted(process_file_list), desc="Reading gps data"): exif = ExifRead(image) timestamp = exif.extract_capture_time() lon, lat = exif.extract_lon_lat() altitude = exif.extract_altitude() if timestamp and lon and lat: geotags.append((timestamp, lat, lon, altitude)) continue if timestamp and (not lon or not lat): missing_geotags.append((image, timestamp)) else: print_error( "Error image {} does not have captured time.".format(image)) return geotags, missing_geotags