[PYTHON] [Old version] Post photos taken with action cams to Mapillary using mapillary_tools

The content of this article is out of date

There was a major version upgrade of mapillary_tools in May 2018, and the usage of the latest version has changed significantly. It is now possible to import location information other than GPX, cut out still images from videos, and automate uploading. How to use the new version is here.

Mapillary is a service that creates Street View by crowdsourcing. Normally, you share what you have taken using the smartphone app, but you can upload the log taken by the GPS logger and the still image taken in the time-lapse mode of the action cam or digital camera together with a script. There are four beautiful seasons in Japan, so please take a lot of pictures and share them at your familiar places and travel destinations. Mapillary's Street View can also be used to edit OpenStreetMap, which will lead to the enhancement of free maps.

About time-lapse photography and GPS logs

I'm using GoPro Hero3 Silver Edition. I'm shooting at 3,680 x 2,760 pixels with an interval of 2 seconds. When shooting with a car, it may be better to have an interval of 1 second on a fast-flowing road if the capacity of the SD card allows. If you can take interval shots of still images at 1-second or 2-second intervals with a camera other than GoPro, you can do it in the same way. Any GPS logger that can output GPX format will do. I'm using GARMIN fenix. Keep the log acquisition interval shorter than the shooting interval.

Operating environment

It runs on Linux Mint 18 Sarah (Python 2.7.12). Maybe Debian and Ubuntu are similar. How to install on MacOSX is described in the Official Documentation.

$ cat /etc/issue
Linux Mint 18 Sarah \n \l
$ python --version
Python 2.7.12


Install the required packages, then branch out from GitHub to clone the older version of mapillary_tools.

$ sudo apt-get install git python-pyexiv2 python-pip python-exif python-pil python-dateutil python-setuptools
$ mkdir ~/src
$ cd ~/src
$ git clone -b add_extra_MAPdata https://github.com/mapillary/mapillary_tools.git

Build and install Python dependent libraries

$ sudo pip install -r requirements.txt

Create environment variable setting script

Create a script that sets the environment variables needed for the script to work.

$ mkdir ~/bin
$ vi ~/bin/mapillary.sh
Environment variable setting shell script contents
item Settings
MAPILLARY_EMAIL The email address you use to log in to Mapilarry
MAPILLARY_PASSWORD The password you use to log in to Mapilarry
MAPILLARY_USERNAME Username registered with Mapilarry
MAPILLARY_PERMISSION_HASH Manual UploadsCopy the value at the bottom of the page
MAPILLARY_SIGNATURE_HASH Manual UploadsCopy the value at the bottom of the page


export MAPILLARY_EMAIL="[email protected]"
export MAPILLARY_PASSWORD="yourpasswd"
export MAPILLARY_USERNAME="Downhill specialty"
export MAPILLARY_PERMISSION_HASH="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
export MAPILLARY_SIGNATURE_HASH="xxxxxxxxxxxxxxxxxxxxxxxxxxxx"

Prepare a place for duplicate photos that will not be uploaded

As mentioned in the help of remove-duplicates.py, the upload script processes directories recursively, so duplicate photo locations should be placed above the upload target directory.

$ mkdir ~/duplicate

Directory structure (example)

├── bin
│   └── mapillary.sh
├── duplicate
├── mapillary
│   ├── 108GOPRO
│   │   ├── G0069921.JPG
│   │   ├── G0069922.JPG
│   │   ├── G0069923.JPG
│ ~~~ (omitted)
│   │   └── G0069998.JPG
│   └── 2016-04-09_150103.gpx
├── src
│   └── mapillary_tools
│       ├── README.md
│ ~~~ (omitted)

Procedure to upload with necessary information to Mapillary

After building the environment, you can execute it from here next time. There are 3 steps.

Read environment variables

If you set it in .bash_profile, you don't have to run it every time.

$ source ~/bin/mapillary.sh

Geotag (recursively)

$ python ~/src/mapillary_tools/python/geotag_from_gpx.py ~/mapillary/ ~/mapillary/2016-04-09_150103.gpx 

Exclude duplicate photos

Exclude those that have been attached to the car and were not moving due to traffic lights or traffic jams, so many pictures of the same place were taken.

$ python ~/src/mapillary_tools/python/remove_duplicates.py ~/mapillary/108GOPRO/ ~/duplicate/

Perform pre-process and upload

The pre-process seems to divide the group, calculate the compass (shooting direction), and add a unique tag.

$ python ~/src/mapillary_tools/python/upload_with_preprocessing.py ~/mapillary/

Finally, enter [y] to commit the transaction. "Success:" and "failed:" in "Uploads:" are always 0.

========= Summary of your uploads ==============
  groups:       4
  total:        2037
  total uploads this run: 2037
  total:        0
  success:      0
  failed:       0
You can now preview your uploads at http://www.mapillary.com/map/upload/im

Finalizing upload will submit all successful uploads and ignore all failed and duplicates.
If all files were marked as successful, everything is fine, just press 'y'.
Finalize upload? [y/n]: y

Script execution supplement

The documentation says upload_with_preprocessing.py has a --remove_duplicates option, but it doesn't work in my environment. So I'm running remove_duplicates.py individually. The spec of this remove_duplicates.py? However, geotag_from_gpx.py and upload_with_preprocessing.py process recursively, but only directly under the specified directory. If the number of shots is large and the DCF folder under DCIM is divided into multiple parts, first combine them into the same folder or execute remove_duplicates.py multiple times. Is it wrong to use, not the specifications? Please let me know if you like.

About interruption, re-execution, and parallel processing

upload_with_preprocessing.py can be interrupted in the middle and resumed by executing it again. If you want to delete the data halfway without resuming after stopping, you can cancel it by accessing Manual Uploads from your browser. Manual Uploads seems to be up to 1 session per person. It seems that it is not possible to execute the upload script while uploading from the browser, or execute two upload scripts in parallel.

Recommended Posts

[Old version] Post photos taken with action cams to Mapillary using mapillary_tools
Post to slack with Python 3
Post to Twitter using Python