def list_images(directory): ''' 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... ''' file_list = [] for root, sub_folders, files in os.walk(directory): file_list += [ os.path.join(root, filename) for filename in files if filename.lower().endswith(".jpg") ] files = [] # get GPS data from the images and sort the list by timestamp for filepath in file_list: metadata = EXIF(filepath) try: t = metadata.extract_capture_time() #lat = metadata["Exif.GPSInfo.GPSLatitude"].value #latRef = metadata["Exif.GPSInfo.GPSLatitudeRef"].value #lon = metadata["Exif.GPSInfo.GPSLongitude"].value #lonRef = metadata["Exif.GPSInfo.GPSLongitudeRef"].value geo = metadata.extract_geo() direction = metadata.extract_direction() files.append( (filepath, geo["latitude"], geo["longitude"], direction)) except KeyError, e: # if any of the required tags are not set the image is not added to the list print("Skipping {0}: {1}".format(filename, e))
def list_images(directory): """ Create a list of image namedtuples sorted by capture timestamp. @param directory: directory with JPEG files @return: a list of image tuples with time, directory, lat,long... """ file_list = [] for root, sub_folders, files in os.walk(directory): 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: metadata = EXIF(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") files.append( Picture_infos._replace(path=filepath, DateTimeOriginal=t, SubSecTimeOriginal=s, Latitude=lat, Longitude=lon, Ele=ele)) # 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) return files