Mapillary Tools is a library for processing and uploading images to Mapillary.
- Quickstart
- Requirements
- Installation
- Usage
- Advanced Usage
- Command Specifications
- Custom Installation
- Development
Install mapillary_tools:
python3 -m pip install --upgrade git+https://github.com/mapillary/mapillary_toolsUpload imagery with mapillary_tools:
mapillary_tools process_and_upload --import_path "path/to/images" --user_name "mapillary_username"To upload images to Mapillary, an account is required and can be created here. When
using the tools for the first time, user authentication is required. You will be prompted to enter your account
credentials. Only Mapillary account credentials (username and password) are valid for authentication
in mapillary_tools. Other Mapillary login options (Facebook, OpenStreetMap, Google+, or ArcGIS) are not supported
with mapillary_tools. If you signed up using one of those services, you can obtain a Mapillary password by requesting
a password reset email through your profile settings or the "Forgot
password?" link on the Mapillary sign-in screen.
To upload images to Mapillary, image GPS and capture time are minimally required. More
information here.
Python 3 (3.6 and above), pip3 and git are required:
python3 -m pip install --upgrade git+https://github.com/mapillary/mapillary_toolsA command line program such as Termux is required. Installation can be done without root privileges. The following commands will install Python 3, pip3, git, and all required libraries for mapillary_tools on Termux:
pkg install python git build-essential libgeos openssl libjpeg-turbo
pip install --upgrade pip wheel
pip install --upgrade git+https://github.com/mapillary/mapillary_toolsTermux must access the device's internal storage to process and upload images. To do this, use the following command:
termux-setup-storageFinally, on devices running Android 11, using a command line program, mapillary_tools will process images very slowly if they are in shared internal storage during processing. It is advisable to first move images to the command line program’s native directory before running mapillary_tools. For an example using Termux, if imagery is stored in the folder “Internal storage/DCIM/mapillaryimages" the following command will move that folder from shared storage to Termux:
mv -v storage/dcim/mapillaryimages mapillaryimagesPython 2 is no longer supported since 0.6.0. If you have to, you can install version 0.5.x from:
- Windows: https://tools.mapillary.com/binary/win/mapillary_tools.exe
- MacOS: https://tools.mapillary.com/binary/osx/mapillary_tools.zip
- Pip install: follow this issue
To sample images from videos, you will also need to install ffmpeg. Review video support.
View additional tips in the Mapillary Help Center or contact Mapillary Support .
All commands are executed with mapillary_tools.
To see the available commands, use the following in the command line (for Windows, adjust the command according the instructions for execution):
mapillary_tools -hExecutable mapillary_tools takes the following arguments:
-h, --help: Show help and exit
--advanced: Use the tools under an advanced level, with additional arguments and commands available
command: Use one of the available commands:
process: Process the images including for instance, geotagging and sequence arrangementupload: Upload images to Mapillaryprocess_and_upload: A bundled command forprocessandupload
See the command specific help for required and optional arguments:
- Show help for
processcommand:
mapillary_tools process -h- Show advanced help for
processcommand:
mapillary_tools process -h --advancedFor Windows, adjust the commands according the instructions for execution.
The command below processes all images in the directory and its sub-directories. It will update the images with
Mapillary-specific metadata in the image EXIF for the user with user name mapillary_user. It requires that each image
in the directory contains capture time and GPS. By default, only the Image Description EXIF tag is overwritten and
duplicate images are flagged to be excluded from upload using default thresholds for duplicate distance 0.1 m and
duplicate angle 5°.
mapillary_tools process --import_path "path/to/images" --user_name "mapillary_username"The command below uploads all images in a directory and its sub-directories. It requires Mapillary-specific metadata in
the image EXIF. It works for images that are captured with Mapillary iOS or Android apps or processed with the process
command.
mapillary_tools upload --import_path "path/to/images"The command below runs process and upload consecutively for a directory.
mapillary_tools process_and_upload --import_path "path/to/images" --user_name "mapillary_username"Available commands for advanced usage:
- Video Specific Commands:
- sample_video
- video_process
- video_process_and_upload
- Process Unit Commands:
- extract_user_data
- extract_import_meta_data
- extract_geotag_data
- extract_sequence_data
- extract_upload_params
- exif_insert
- Other Commands:
- process_csv
- interpolate
- authenticate
- post_process
- Run process and upload consecutively, while process is reading geotag data from a gpx track. It requires
that
capture timeinformation is embedded in the image EXIF. By default geotag data is stored only in the mapillary image description, in the EXIF Image Description tag. If you would like the rest of the tags to be overwritten as well, for example to be able to place images on the map for testing purposes, you should pass an additional argument--overwrite_all_EXIF_tagsto overwrite all EXIF tags, or in case you only want to overwrite a specific tag, like for example the GPS tag, pass argument--overwrite_EXIF_gps_tag.
mapillary_tools process --advanced --import_path "path/to/images" \
--user_name "mapillary_username" \
--geotag_source "gpx" \
--geotag_source_path "path/to/gpx_file"
mapillary_tools upload --import_path "path/to/images"or
mapillary_tools process_and_upload --advanced --import_path "path/to/images" \
--user_name "mapillary_username" \
--geotag_source "gpx" \
--geotag_source_path "path/to/gpx_file"- To prevent data loss or control versions, the original images can be left intact by specifying the
flag
--keep_original. This will result in the edited image being saved in a copy of the original image, instead of the original image itself. Copies are saved in{$import_path/$image_path/}.mapillary/process_images}and are deleted at the start of every processing run.
mapillary_tools process --advanced --import_path "path/to/images" \
--user_name "mapillary_username" \
--keep_original
mapillary_tools upload --import_path "path/to/images"or
mapillary_tools process_and_upload --advanced --import_path "path/to/images" \
--user_name "mapillary_username" \
--keep_original- Derive image direction (image heading or camera angle) based on image latitude and longitude. If images are missing
direction, the direction is derived automatically, if direction is present, it will be derived and overwritten only if
the flag
--interpolate directionsis specified.
mapillary_tools process --advanced --import_path "path/to/images" \
--user_name "mapillary_username" \
--interpolate_directions
mapillary_tools upload --import_path "path/to/images"or
mapillary_tools process_and_upload --advanced --import_path "path/to/images" \
--user_name "mapillary_username" \
--interpolate_directions- Sample the video(s) located in
path/to/videosinto the directorypath/to/images, at a sample interval of 0.5 seconds and tag the sampled images withcapture time. Note that the video frames will always be sampled into sub directory.mapillary/sampled_video_frames/"video_import_path", whether import path is specified or not. In caseimport_pathis specified the final path for the sampled video frames will be"import path"/.mapillary/sampled_video_frames/"video_import_path"and in caseimport_pathis not specified, the final path for the sampled video frames will bepath/to/.mapillary/sampled_video_frames/"video_import_path".
mapillary_tools sample_video --import_path "path/to/images" \
--video_import_path "path/to/videos" \
--video_sample_interval 0.5 --advanced - Sample the video(s) located in
path/to/videos, at a sample interval of 2 seconds (default value) and tag the resulting images withcapture time. And then process and upload the resulting images for userusername_at_mapillary, specifying a gpx track to be the source of geotag data. Additionally pass the--overwrite_all_EXIF_tagsso the extracted frames have all the tags set beside the Image Description tag.
mapillary_tools sample_video --video_import_path "path/to/videos" --advanced
mapillary_tools process --advanced --import_path "path/to/.mapillary/sampled_video_frames/video_import_path" \
--user_name "mapillary_username" \
--geotag_source "gpx" \
--geotag_source_path "path/to/gpx_file" \
--overwrite_all_EXIF_tags
mapillary_tools upload --import_path "path/to/.mapillary/sampled_video_frames/video_import_path"or
mapillary_tools video_process_and_upload --video_import_path "path/to/videos" \
--user_name "mapillary_username" \
--advanced --geotag_source "gpx" \
--geotag_source_path "path/to/gpx_file" \
--overwrite_all_EXIF_tags- Insert image capture time and gps data from a csv file, based on filename:
mapillary_tools process_csv --import_path "path/to/images" \
--csv_path "path/to/csv_file" \
--filename_column 1 \
--timestamp_column 4 \
--latitude_column 2 \
--longitude_column 3 \
--advanced- Insert image capture time and meta data from a csv file based on the order of image file names (in case filename column is missing):
mapillary_tools process_csv --import_path "path/to/images" \
--csv_path "path/to/csv_file" \
--timestamp_column 1 \
--meta_columns "6,7" \
--meta_names "random_name1,random_name2" \
--meta_types "double,string" \
--advancedThe process command will format the required and optional meta data into a Mapillary image description and insert it
in the image EXIF Image Description tag. Images are required to contain image capture time, latitude, longitude and
camera direction in the image EXIF. Under advanced usage, additional functionalities are available, for example latitude
and longitude can be read from a gpx track file or a GoPro video, camera direction can be derived based on latitude and
longitude, duplicates can be kept instead of excluded from the upload etc. See the command specific help for required
and optional arguments, add --advanced to see additional advanced optional arguments.
- process all images for user
mapillary_user, in the directorypath/to/imagesand its sub-directories:
mapillary_tools process --import_path "path/to/images" \
--user_name "mapillary_username"- process all images for user
mapillary_user, in the directorypath/to/images, skipping the images in its sub-directories, rerunning process for all images that were not already uploaded and printing out extra warnings or errors.
mapillary_tools process --import_path "path/to/images" \
--user_name "mapillary_username" \
--verbose \
--rerun \
--skip_subfolders- Process all images for user
mapillary_user, in the directorypath/to/imagesand its sub-directories, reading geotag data from a gpx track stored in filepath/to/gpx_file, specifying an offset of 2 seconds between the camera and gps device, ie, camera is 2 seconds ahead of the gps device and specifying to keep duplicates to be uploaded instead of flagging images as duplicates in case they are apart by equal or less then the default 0.1 m and differ by the camera angle by equal or less than the default 5°. Additionally pass the--overwrite_EXIF_gps_tagto overwrite values with the values obtained from the gpx track.
mapillary_tools process --import_path "path/to/images" \
--user_name "mapillary_username" \
--advanced \
--geotag_source "gpx" \
--geotag_source_path "path/to/gpx_file" \
--offset_time 2 \
--keep_duplicates \
--overwrite_EXIF_gps_tag- Process all images for user
mapillary_user, in the directorypath/to/imagesand its sub-directories, specifying the import to be private imagery belonging to an organization with organization usernamemapillary_organization. You can find the organization username in your dashboard.
mapillary_tools process --import_path "path/to/images" \
--user_name "mapillary_username" \
--advanced \
--private \
--organization_username "mapillary_organization"- Process all images for user
mapillary_user, in the directorypath/to/imagesand its sub-directories, specifying an angle offset of 90° for the camera direction and splitting images into sequences of images apart by less than 100 meters according to imageGPSand less than 120 seconds according to imagecapture time. Additionally pass the--overwrite_EXIF_direction_tagto overwrite values with the additional specified offset.
mapillary_tools process --import_path "path/to/images" \
--user_name "mapillary_username" \
--advanced \
--offset_angle 90 \
--cutoff_distance 100 \
--cutoff_time 120 \
--overwrite_EXIF_direction_tagImages that have been successfully processed or were taken with the Mapillary app will contain the required Mapillary
image description embedded in the image EXIF and can be uploaded with the upload command.
The upload command will collect all the images in the import path, while checking for duplicate flags, processing and
uploading logs. If image is flagged as duplicate, was logged with failed process or logged as successfully uploaded, it
will not be added to the upload list.
By default, 5 threads upload in parallel and the script retries 50 times upon encountering a failure. These can be
customized by specifying additional arguments --number_threads and --max_attempts under --advanced usage or with
environment variables in the command line:
NUMBER_THREADS=10
MAX_ATTEMPTS=100
- upload all images in the directory
path/to/imagesand its sub directories:
mapillary_tools upload --import_path "path/to/images"- upload all images in the directory
path/to/images, while skipping its sub directories and specifying to upload with 10 threads and 10 maximum attempts:
mapillary_tools upload --import_path "path/to/images" \
--skip_subfolders \
--number_threads 10 \
--max_attempts 10 \
--advancedprocess_and_upload command will run process and upload commands consecutively with combined required and optional
arguments.
- process and upload all the images in directory
path/to/imagesand its sub-directories for usermapillary_user.
mapillary_tools process_and_upload --import_path "path/to/images" \
--user_name "mapillary_username"- Process and upload all the images in directory
path/to/imagesand its sub-directories for usermapillary_user, while specifying duplicate distance and angle threshold so that duplicate images are consecutive images that are less than 0.5 meter apart according to imageGPSand have less than 1° camera angle difference according to image direction.
mapillary_tools process_and_upload --import_path "path/to/images" \
--user_name "mapillary_username" \
--verbose \
--rerun \
--duplicate_distance 0.5 \
--duplicate_angle 1 \
--advancedsample_video command will sample a video into images and insert capture time to the image EXIF. Capture time is
calculated based on the video start time and sampling interval. Video start time can either be extracted from the
video metadata or passed as an argument --video_start_time (milliseconds since UNIX epoch).
- Sample the video(s) located in
path/to/videosat the default sampling rate 2 seconds, ie 1 video frame every 2 seconds. Video frames will be sampled into a sub directory.mapillary/sampled_video_frames/video_import_pathat the location of the video.
mapillary_tools sample_video --video_import_path "path/to/videos" --advanced- Sample the video(s) located in
path/to/videosto directorypath/to/imagesat a sampling rate 0.5 seconds, ie two video frames every second and specifying the video start time to be156893940910(milliseconds since UNIX epoch).
mapillary_tools sample_video --import_path "path/to/images" \
--video_import_path "path/to/videos" \
--video_sample_interval 0.5 \
--video_start_time 156893940910 \
--advancedvideo_process command will run video_sample and process commands consecutively with combined required and optional
arguments.
- In case video start capture time could not be extracted or specified, images should be tagged with
capture timefrom the external geotag source, by passing the argument--use_gps_start_time. To make sure the external source and images are aligned ok, an offset in seconds can be specified.
mapillary_tools video_process --import_path "path/to/images" \
--video_import_path "path/to/videos" \
--user_name "mapillary_username" --advanced \
--geotag_source "gpx" \
--geotag_source_path "path/to/gpx" \
--use_gps_start_time \
--offset_time 2video_process_and_upload command will run video_sample, process and upload commands consecutively with combined
required and optional arguments.
- Sample the video(s) located in
path/to/videosto directorypath/to/imagesat the default sampling rate 1 second, ie one video frame every second. Process and upload resulting video frames for usermapillary_user, reading geotag data from a gpx track stored inpath/to/gpx_filevideo, assuming video start time can be extracted from the video file and deriving camera direction based onGPS.
mapillary_tools video_process_and_upload --import_path "path/to/images" \
--video_import_path "path/to/videos" \
--user_name "mapillary_username" \
--advanced \
--geotag_source "gpx" \
--geotag_source_path "path/to/gpx_file" \
--video_sample_interval 1 \
--interpolate_directionsProcess unit commands are commands executed by the process command. Usage of process unit commands requires the
flag --advanced to be passed and might require some experience with mapillary_tools.
extract_user_data will process user specific properties and initialize authentication in case of first import.
Credentials are then stored in a global config file and read from there in further imports.
extract_import_meta_data will process import specific meta data which is not required, but can be very useful. Import
meta data is read from EXIF and/or can be passed through additional arguments.
extract_geotag_data will process image capture date/time, latitude, longitude and camera angle. By default geotag data
is read from image EXIF. Under advanced usage, a different source of latitude, longitude and camera direction can be
specified. Geotagging can be adjusted for better quality, by specifying an offset angle for the camera direction or an
offset time between the camera and gps device.
extract_sequence_data will process the entire set of images located in the import path and create sequences, initially
based on the file system structure, then based on image capture time and location and in the end splitting sequences
longer than 500 images. By default, duplicates are flagged to be excluded from upload, using the default duplicate
thresholds for distance 0.1 m and angle 5°. Optionally, duplicates can be kept and camera directions can be derived
based on latitude and longitude.
extract_upload_params will process user specific upload parameters, required to safely upload images to Mapillary.
exif_insert will take all the meta data read and processed in the other processing unit commands and insert it in the
image EXIF tag Image Description only, unless additional arguments are passed in order to overwrite the rest of EXIF
tags as well.
authenticate will update the user credentials stored in ~/.config/mapillary/config. Mapillary acount user_name
, user_email and user_password are required and can either be passed as arguments to the command or left unspecified
and entered upon prompt.
interpolate will interpolate identical timestamps in a csv file or stored in image EXIF or will interpolate missing
gps data in a set of otherwise geotagged images.
process_csv will parse the specified csv file and insert data in the image EXIF.
post_process provides functionalities to help summarize and organize the results of the process and/or upload
commands.
- Sample one or more Blackvue videos in directory
path/to/videosinto import pathpath/to/imagesat a sampling rate 0.2 seconds, ie 5 frames every second and process resulting video frames for usermapillary_user, reading geotag data from the Blackvue videos inpath/to/videosand specifying camera make and model, specifying to derive camera direction based onGPSand use theGPSstart time. Note that video frames will be sampled intopath/to/images/.mapillary/sampled_video_frames/"video_import_path". Video frames will be geotagged after all the videos in the specifiedvideo_import_pathhave been sampled. In case video frames geotagging requiresrerun, there is no need to rerun the entirevideo_processcommand, in case video frame extraction was successful, rerunning only theprocesscommand for the givenimport_pathis sufficient. We encourage users to check and specify camera make and model, since it helps with camera calibration and improves 3D reconstruction. If you want to check the video frame placement on the map before uploading, specify--overwrite_EXIF_gps_tag.
mapillary_tools video_process --import_path "path/to/images" \
--video_import_path "path/to/videos" \
--user_name "mapillary_username" \
--advanced \
--geotag_source "blackvue_videos" \
--geotag_source_path "path/to/videos" \
--use_gps_start_time \
--interpolate_directions \
--video_sample_interval 0.2 \
--device_make "Blackvue" \
--device_model "DR900S-2CH" \
--overwrite_EXIF_gps_tag- Sample one or more GoPro videos in directory
path/to/videosinto import pathpath/to/imagesat a sampling rate 0.5 seconds, ie 2 frames every second and process resulting video frames for usermapillary_user, reading geotag data from the GoPro videos inpath/to/videosand specifying to derive camera direction based onGPS. Note that video frames will be sampled intopath/to/images/.mapillary/sampled_video_frames/"video_import_path". Video frames will be geotagged after all the videos in the specifiedvideo_import_pathhave been sampled. In case video frames geotagging requiresrerun, there is no need to rerun the entirevideo_processcommand, in case video frame extraction was successful, rerunning only theprocesscommand for the givenimport_pathis sufficient. If you want to check the video frame placement on the map before uploading, specify--overwrite_EXIF_gps_tag.
mapillary_tools video_process --import_path "path/to/images" \
--video_import_path "path/to/videos" \
--user_name "mapillary_username" \
--advanced \
--geotag_source "gopro_videos" \
--geotag_source_path "path/to/videos" \
--interpolate_directions \
--video_sample_interval 0.5 \
--overwrite_EXIF_gps_tagTo sample images from videos, you will also need to install ffmpeg.
To install ffmpeg on Windows, follow
these instructions.
To install ffmpeg on macOS use Homebrew. Once you have Homebrew installed, you can install ffmpeg
by running:
brew install ffmpegTo install ffmpeg on Ubuntu:
sudo apt install ffmpegRunning the executable mapillary_tools is slightly different on Unix and Windows OS.
On Windows, the executable mapillary_tools is installed under the python's Scripts and needs to be inserted in the
PATH manually. At the same time, the interpreter program python needs to be specified, as the interpreter directive in
the executable is specified for Unix OS. Path to the interpreter program python needs to be available in the PATH.
Example of usage, in case python and mapillary_tools are available in the PATH:
python mapillary_tools
in case of issues with editing PATH, both python and mapillary_tools can be specified with the absolute path:
C:\python27\python.exe C:\python27\Scripts\mapillary_tools
note that the location of the python interpreter program and scripts installed as python scripts can be different
depending on the Windows and Python versions. Therefore users need to check the exact paths locally before running.
On Ubuntu and MacOSX the executable is available in the PATH after installation and can be used as is (no need to
specify python as the interpreter program and no need for setting up the PATH or providing the absolute path to
executable, no matter where in the command line you are located).
In case of any issues with the installation and usage of mapillary_tools, check this section in case it has already
been addressed, otherwise, open an issue on Github.
- In case of any issues, it is always safe to try and rerun the failing command while specifying
--verboseto see more information printed out. Uploaded images should not get uploaded more than once and should not be processed after uploading. mapillary_tools should take care of that, if it occurs otherwise, please open an issue on Github. - Make sure you run the latest version of
mapillary_tools, which you can check withmapillary_tools --version. When installing the latest version, dont forget you need to specify--upgrade. - Advanced user are encouraged to explore the processed data and log files in
the
{image_path}/.mapillary/logs/{image_name}/to get more insight in the failure.
- If having issues installing
pipwithbrewon macOS, one solution issudo easy_install pip. If the installed version is not appropriate then upgrade withsudo pip install --upgrade pip.
-
HTTP Errors can occur due to poor network connection or high load on the import pipeline. In most cases the images eventually get uploaded regardless. But in some cases HTTP Errors can occur due to authentication issues, which can be resolved by either removing the config file with the users credentials, located in
~/.config/mapillary/configor running theauthenticatecommand available under advanced usage ofmapillary_tools. -
Windows users sometimes have issues with the prompt not functioning. This usually results in mapillary_tools just hanging without printing anything or creating any logs in
{image_path}/.mapillary/logs/{image_name}. In such cases authentication should be run separately with theauthenticationcommand, while passinguser_name,user_emailanduser_passwordas command line arguments. This will avoid the prompt and will authenticate the user for all further usage of theprocesscommand. -
Missing required data is often the reason for failed uploads, especially if the processing included parsing external data like a gps trace. Images are aligned with a gps trace based on the image capture time and gps time, where the default assumption is that both are in UTC. Check the begin and end date of your capture and the begin and end date of the gps trace to make sure that the image capture time is in the scope of the gps trace. To correct any offset between the two capture times, you can specify
--offset_time "offset time". Timezone differences can result in such issues, if you know that the image capture time was stored in your current local timezone, while the gps trace is stored in UTC, specify--local_time. If images do not contain capture time or the capture time is unreliable, while gps time is accurate, specifyuse_gps_start_time. -
In cases where the
import_pathis located on an external mount, images can potentially get overwritten, if breaking the script with Ctrl+c. To keep the images intact, you can specify--keep_originaland all the processed data will be inserted in a copy of the original image. We are still in progress of improving this step of data import and will make sure that no image gets overwritten at any point. -
GIS users on Windows using Custom Installation, particularly ArcMap users, who have Python 2.7 version with pip already installed, should add these paths in the system PATH, to avoid compatibility issues:
-
executing
python:C:\Python27\ArcGIS10.x -
executing
pip;C:\Python27\ArcGIS10.x\Scripts
- Some devices do not store the camera direction properly, often storing only 0. Camera direction will get derived based
on latitide and longitude only if the camera direction is not set or
--interpolate_directionsis specified. Before processing and uploading images, make sure that the camera direction is either correct or missing and in case it is present but incorrect, you specify-interpolate_directions. - Timestamp interpolation is required in case the latitude and longitude are stored in an external gps trace with a
higher capture frequency then the image capture frequency which results in identical image capture times.
Command
interpolatecan be used to interpolate image capture time:
mapillary_tools interpolate --data "identical_timestamps" --import_path "path/to/images" --advanced - If
processincludes correction of existing EXIF tag values or extraction of missing EXIF tag values from external sources and you want to test the placement on the map before uploading the images, make sure you pass--advanced --overwrite_all_EXIF_tagsso that the rest of tags beside Image Description tag will get updated with the values obtained duringprocess.
Clone the repository:
git clone git@github.com:mapillary/mapillary_tools.git
cd mapillary_toolsSet up the virtual environment. It is optional but recommended:
python3 -m venv venv
source venv/bin/activate
# verify if the venv is activated
which python3Install dependencies:
python3 -m pip install -r requirements.txt
python3 -m pip install -r requirements-dev.txt
Run the code from the repository:
python3 -m mapillary_tools --version
Run tests:
pytest tests
Run linting:
black mapillary_tools tests