def download_photos(meta, image_path): """Download photos given export metadata.""" photos = meta["photos"] num_photo = len(photos) photo_files = [] for i, p in enumerate(photos): io.progress(i + 1, num_photo, "{}/{}".format(i + 1, num_photo)) url = p["photo_file_url"] photo_file = download_path(image_path, p["photo_id"]) if not os.path.isfile(photo_file): urllib.urlretrieve(url, photo_file) meta["photos"][i]["photo_file_path"] = photo_file photo_files.append("{}.jpg".format(p["photo_id"])) with open(download_done_file(image_path), "wb") as f: f.write("\n".join(photo_files)) return photo_files
upload_token = get_upload_token(MAPILLARY_EMAIL, MAPILLARY_PASSWORD) project_key = get_project_key(project_key) else: MAPILLARY_USERNAME, MAPILLARY_EMAIL, MAPILLARY_PASSWORD = None, None, None upload_token = None with open(json_path, "rb") as f: metadata = json.loads(f.read()) if output_path is not None and os.path.exists(output_path) is False: os.makedirs(output_path) else: output_path = "" images = os.listdir(image_path) for i, f in enumerate(images): if f.lower().endswith( ('jpg', 'jpeg', 'png', 'tif', 'tiff', 'pgm', 'pnm', 'gif')): output_file = os.path.join(output_path, os.path.basename(f)) if f in metadata: add_mapillary_description(os.path.join(image_path, f), MAPILLARY_USERNAME, MAPILLARY_EMAIL, project_key, upload_token, metadata[f], output_file) else: print "Missing metadata for {}, skipping...".format(f) progress(i, len(images)) else: print "Ignoring {0}".format(os.path.join(image_path, f))
# Get duration of the video video_duration = get_video_duration(video_file) gps_duration = (points[-1][0] - points[0][0]) # Sample video if not args.skip_sampling: sample_video(video_file, image_path, sample_interval, video_type) # Add EXIF data to sample images image_list = list_images(image_path) print "Adding EXIF to {} images".format(len(image_list)) missing_gps = 0 for i, im in enumerate(image_list): io.progress(i, len(image_list)) timestamp = timestamp_from_filename(os.path.basename(im), sample_interval, start_time, video_duration, time_offset, duration_ratio) try: lat, lon, bearing, altitude = geo.interpolate_lat_lon( points, timestamp) data = { "lat": lat, "lon": lon, "altitude": altitude, "capture_time": timestamp, "bearing": (bearing + args.offset_angle) % 360, "make": make,
for project in projects: print project['name'] print "Could not find project name '%s' in your projects, exiting." % project_name sys.exit() if path.lower().endswith(".jpg"): # single file file_list = [path] else: # folder(s) file_list = [] for root, sub_folders, files in os.walk(path): file_list += [ os.path.join(root, filename) for filename in files if filename.lower().endswith(".jpg") ] num_file = len(file_list) for i, filepath in enumerate(file_list): base, filename = os.path.split(filepath) io.progress(i + 1, num_file) exif = pyexiv2.ImageMetadata(filepath) exif.read() description_ = exif['Exif.Image.ImageDescription'].value imgDesc = json.loads(description_) if 'MAPSettingsProject' not in imgDesc or overwrite: imgDesc['MAPSettingsProject'] = project_key exif['Exif.Image.ImageDescription'].value = json.dumps(imgDesc) exif.write() print "Done, processed %s files" % len(file_list)