예제 #1
0
def parse_gps_trace(gps_trace_file, local_time=False):
    points = None
    if gps_trace_file.lower().endswith(".gpx"):
        points = get_lat_lon_time_from_gpx(gps_trace_file, local_time)
    elif gps_trace_file.lower().endswith(".nmea"):
        points = get_lat_lon_time_from_nmea(gps_trace_file, local_time)
    elif gps_trace_file.lower().endswith(".srt"):
        pass
    return points
예제 #2
0
def geotag_from_gpx(piclists, gpx_file, offset_time=0, offset_bearings=0, offset_distance=0):
    """This function will try to find the location (lat lon) for each pictures in each list, compute the direction
    of the pictures with an offset if given, and offset the location with a distance if given. Then, these
    coordinates will be added in the New_Picture_infos namedtuple.
    :param piclists: a list of of list of New_Picture_infos namedtuple
    :param gpx_file: a gpx or nmea file path
    :param offset_time: time offset between the gpx/nmea file, and the image's timestamp
    :param offset_bearings: the offset angle to add to the direction of the images (for side camera)
    :param offset_distance: a distance (in meter) to move the image from the computed location. (Use this setting to
    not have all the images from a multicam setup at the same exact location
    :return: nothing, the function update the New_Picture_infos namedtuple inside the lists"""
    now = datetime.datetime.now(tzlocal())
    print("Your local timezone is {0}, if this is not correct, your geotags will be wrong.".format(
        now.strftime('%Y-%m-%d %H:%M:%S %z')))

    # read gpx file to get track locations
    if gpx_file.lower().endswith(".gpx"):
        gpx = get_lat_lon_time_from_gpx(gpx_file)
    elif gpx_file.lower().endswith(".nmea"):
        gpx = get_lat_lon_time_from_nmea(gpx_file)
    else:
        print("\nWrong gnss file! It should be a .gpx or .nmea file.")
        sys.exit()

    for piclist, offset_bearing in zip(piclists, offset_bearings):

        start_time = time.time()
        print("===\nStarting geotagging of {0} images using {1}.\n===".format(len(piclist), gpx_file))

        # for filepath, filetime in zip(piclist.path, piclist.New_DateTimeOriginal):
        for i, pic in enumerate(piclist):
            # add_exif_using_timestamp(filepath, filetime, gpx, time_offset, bearing_offset)
            # metadata = ExifEdit(filename)
            t = pic.New_DateTimeOriginal - datetime.timedelta(seconds=offset_time)
            try:
                lat, lon, bearing, elevation = interpolate_lat_lon(gpx, t)
                corrected_bearing = (bearing + offset_bearing) % 360
                # Apply offset to the coordinates if distance_offset exists
                if offset_distance != 0:
                    new_Coords = LatLon(lat, lon).offset(corrected_bearing, offset_distance / 1000)
                    lat = new_Coords.lat.decimal_degree
                    lon = new_Coords.lon.decimal_degree
                # Add coordinates, elevation and bearing to the New_Picture_infos namedtuple
                piclist[i] = pic._replace(Longitude=lon, Latitude=lat, Ele=elevation, ImgDirection=corrected_bearing)

            except ValueError, e:
                print("Skipping {0}: {1}".format(pic.path, e))

        print("Done geotagging {0} images in {1:.1f} seconds.".format(len(piclist), time.time() - start_time))
예제 #3
0
        # folder(s)
        file_list = []
        for root, sub_folders, files in os.walk(args.path):
            files.sort()
            file_list += [
                os.path.join(root, filename) for filename in files
                if filename.lower().endswith(".jpg")
            ]

    # start time
    start_time = time.time()

    # Estimate capture time with sub-second precision
    sub_second_times = estimate_sub_second_time(file_list, args.interval)
    if not sub_second_times:
        sys.exit(1)

    # read gpx file to get track locations
    gpx = get_lat_lon_time_from_gpx(args.gpx_file)

    print("===\nStarting geotagging of {0} images using {1}.\n===".format(
        len(file_list), args.gpx_file))

    for filepath, filetime in zip(file_list, sub_second_times):
        add_exif_using_timestamp(filepath, filetime, gpx, args.time_offset,
                                 args.bearing_offset)

    print("Done geotagging {0} images in {1:.1f} seconds.".format(
        len(file_list),
        time.time() - start_time))
예제 #4
0
    else:
        # folder(s)
        file_list = []
        for root, sub_folders, files in os.walk(args.path):
            files.sort()
            file_list += [
                os.path.join(root, filename) for filename in files
                if filename.lower().endswith(".jpg")
            ]

    # start time
    start_time = time.time()

    # Estimate capture time with sub-second precision
    sub_second_times = estimate_sub_second_time(file_list, args.interval)
    if not sub_second_times:
        sys.exit(1)

    # read gpx file to get track locations
    gpx = get_lat_lon_time_from_gpx(args.gpx_file, args.local_time)

    print("===\nStarting geotagging of {0} images using {1}.\n===".format(
        len(file_list), args.gpx_file))

    for filepath, filetime in zip(file_list, sub_second_times):
        add_exif_using_timestamp(filepath, filetime, gpx, args.time_offset,
                                 args.bearing_offset)

    print("Done geotagging {0} images in {1:.1f} seconds.".format(
        len(file_list),
        time.time() - start_time))
예제 #5
0
    now = datetime.datetime.now(tzlocal())
    print("Your local timezone is {0}, if this is not correct, your geotags will be wrong.".format(now.strftime('%Y-%m-%d %H:%M:%S %Z')))

    if args.path.lower().endswith(".jpg"):
        # single file
        file_list = [args.path]
    else:
        # folder(s)
        file_list = []
        for root, sub_folders, files in os.walk(args.path):
            files.sort()
            file_list += [os.path.join(root, filename) for filename in files if filename.lower().endswith(".jpg")]

    # start time
    start_time = time.time()

    # Estimate capture time with sub-second precision
    sub_second_times = estimate_sub_second_time(file_list, args.interval)
    if not sub_second_times:
        sys.exit(1)

    # read gpx file to get track locations
    gpx = get_lat_lon_time_from_gpx(args.gpx_file)

    print("===\nStarting geotagging of {0} images using {1}.\n===".format(len(file_list), args.gpx_file))

    for filepath, filetime in zip(file_list, sub_second_times):
        add_exif_using_timestamp(filepath, filetime, gpx, args.time_offset, args.bearing_offset)

    print("Done geotagging {0} images in {1:.1f} seconds.".format(len(file_list), time.time()-start_time))