def geotag_from_gps_trace(process_file_list, geotag_source, geotag_source_path, offset_time=0.0, offset_angle=0.0, local_time=False, sub_second_interval=0.0, use_gps_start_time=False, verbose=False): # print time now to warn in case local_time if local_time: now = datetime.datetime.now(tzlocal()) print("Your local timezone is {0}. If not, the geotags will be wrong." .format(now.strftime('%Y-%m-%d %H:%M:%S %Z'))) else: # if not local time to be used, warn UTC will be used print("It is assumed that the image timestamps are in UTC. If not, try using the option --local_time.") # read gps file to get track locations if geotag_source == "gpx": gps_trace = get_lat_lon_time_from_gpx(geotag_source_path, local_time) elif geotag_source == "nmea": gps_trace = get_lat_lon_time_from_nmea(geotag_source_path, local_time) # Estimate capture time with sub-second precision, reading from image EXIF sub_second_times = estimate_sub_second_time(process_file_list, sub_second_interval) if not sub_second_times: print_error( "Error, capture times could not be estimated to sub second precision, images can not be geotagged.") create_and_log_process_in_list(process_file_list, "geotag_process" "failed", verbose) return if not gps_trace: print_error("Error, gps trace file {} was not read, images can not be geotagged.".format( geotag_source_path)) create_and_log_process_in_list(process_file_list, "geotag_process", "failed", verbose) return if use_gps_start_time: # update offset time with the gps start time offset_time += (sorted(sub_second_times) [0] - gps_trace[0][0]).total_seconds() for image, capture_time in tqdm(zip(process_file_list, sub_second_times), desc="Inserting gps data into image EXIF"): if not capture_time: print_error( "Error, capture time could not be extracted for image " + image) create_and_log_process(image, "geotag_process", "failed", verbose=verbose) geotag_properties = get_geotag_properties_from_gps_trace( image, capture_time, gps_trace, offset_angle, offset_time, verbose) create_and_log_process(image, "geotag_process", "success", geotag_properties, verbose)
def geotag_from_gpx(process_file_list, import_path, geotag_source_path, offset_time=0.0, offset_angle=0.0, local_time=False, sub_second_interval=1.0, use_gps_start_time=False, verbose=False): # print time now to warn in case local_time if local_time: now = datetime.datetime.now(tzlocal()) if verbose: print("Your local timezone is {0}. If not, the geotags will be wrong." .format(now.strftime('%Y-%m-%d %H:%M:%S %Z'))) else: # if not local time to be used, warn UTC will be used if verbose: print( "It is assumed that the image timestamps are in UTC. If not, try using the option --local_time.") # read gpx file to get track locations gpx = get_lat_lon_time_from_gpx(geotag_source_path, local_time) # Estimate capture time with sub-second precision, reading from image EXIF sub_second_times = estimate_sub_second_time(process_file_list, sub_second_interval) if not sub_second_times: if verbose: print("Error, capture times could not be estimated to sub second precision, images can not be geotagged.") create_and_log_process_in_list(process_file_list, import_path, "geotag_process" "failed", verbose) return if not gpx: if verbose: print("Error, gpx file was not read, images can not be geotagged.") create_and_log_process_in_list(process_file_list, import_path, "geotag_process" "failed", verbose) return if use_gps_start_time: # update offset time with the gps start time offset_time += (sub_second_times[0] - gpx[0][0]).total_seconds() for image, capture_time in zip(process_file_list, sub_second_times): if not capture_time: if verbose: print("Error, capture time could not be extracted for image " + image) create_and_log_process(image, import_path, "geotag_process", "failed", verbose=verbose) geotag_properties = get_geotag_properties_from_gpx( image, capture_time, gpx, offset_angle, offset_time, verbose) create_and_log_process(image, import_path, "geotag_process", "success", geotag_properties, verbose)