Пример #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 get_image_list(path_to_pics):
    """
        Create a list of image tuples sorted by capture timestamp.
        @param directory: directory with JPEG files
        @return: a list of image tuples with time, directory, lat,long...
        :param path_to_pics:
        """
    print("Searching for jpeg images in ", path_to_pics, end=" ")
    file_list = []
    for root, sub_folders, files in os.walk(path_to_pics):
        file_list += [
            os.path.join(root, filename) for filename in files
            if filename.lower().endswith(".jpg")
        ]

    files = []
    # get DateTimeOriginal data from the images and sort the list by timestamp
    for filepath in file_list:
        #print(filepath)
        metadata = EXIFRead(filepath)
        try:
            t = metadata.extract_capture_time()
            s = int(t.microsecond / 1000000)
            geo = metadata.extract_geo()
            lat = geo.get("latitude")
            lon = geo.get("longitude")
            ele = geo.get("altitude")
            direction = metadata.extract_direction()
            files.append(
                Picture_infos._replace(path=filepath,
                                       DateTimeOriginal=t,
                                       SubSecTimeOriginal=s,
                                       Latitude=lat,
                                       Longitude=lon,
                                       Ele=ele,
                                       ImgDirection=direction))
            # print t
            # print type(t)
        except KeyError as e:
            # if any of the required tags are not set the image is not added to the list
            print("Skipping {0}: {1}".format(filepath, e))

    files.sort(key=lambda file: file.DateTimeOriginal)
    # print_list(files)

    print("{:5} found".format(len(files)))
    return files