GIS595/MEA792:
UAV/lidar Data Analytics

This is an unmaintained course material, please see current material at:

Processing of UAS imagery in OpenDroneMap

We will reconstruct DSM and create orthophoto in OpenDroneMap - open source toolkit for processing civilian drone imagery.

Setting up OpenDroneMap in virtual machine

We will run OpenDroneMap in virtual machine to simplify setup on different platforms (the guest machine is Ubuntu). OpenDroneMap doesn't have GUI, we will run it in command line, which is quite simple.
  1. Download and install VirtualBox for your platform if you don't have it already.
  2. We need bash command line. If you are using Windows, download Git for Windows unless you already have some shell.
  3. Install Vagrant.
  4. Either in file manager or in command line create a directory somewhere called 'odm'. Inside 'odm' create directory 'vagrant' and 'data' (directory 'data' will be our shared folder):
    mkdir odm
    cd odm
    mkdir vagrant
    mkdir data
    
  5. Download this Vagrantfile (based on ODM Vagrantfile) to the newly created folder 'odm/vagrant'. This files describes settings of the virtual machine we are about to create. I suggest to change the number of CPUs and available memory based on your computer. Change the values in vb.cpus and vb.customize ["modifyvm", :id, "--memory", "4096"] depending how much you want to use your coomputer for other things during the computation. I recommend however to give it as much memory a you can. If it doesn't have enough memory, it will finish with an error.
  6. Copy your photos and log into directory 'odm/data'. Unzip it directly into this directory (no subdirectory).
  7. Open your command line and cd to your 'odm/vagrant' directory:
    vagrant up
    vagrant ssh
    
    You have now installed, launched and logged in to an Ubuntu GNU/Linux OS.
  8. On the guest machine install git and download ODM repository:
    sudo apt-get -y install git
    sudo mkdir /odm_app
    sudo chown vagrant:vagrant /odm_app/
    cd /odm_app/
    git clone https://github.com/OpenDroneMap/OpenDroneMap.git
    
  9. Install ODM.
    cd OpenDroneMap
    ./install.sh
    
    During installation all dependecies are automatically downloaded and compiled. This will take approximately half an hour. If successfull, you will see "script finished" in the end. Now you are ready to start the computation.
  10. You can shutdown the virtual machine when you don't use it:
    sudo shutdown now
    
    You can start it anytime by cd to your 'odm/vagrant' and typing:
    vagrant ssh
    If you need to make any changes to the virtual machine specification, for example number of CPUs or memory, shutdown the machine from host:
    vagrant halt
    
    change the Vagrant file and re-initialize the machine:
    vagrant up
    

Preprocesing of images

OpenDroneMap takes GPS position and focal length from images, not from the log. Since the images don't have this information in their EXIF data, we will have to add them there. We will need to convert the .jxl log file into a csv file using Vasek's script. Then we need to upload the focal length and GPS into the photos' EXIF data, because our photos don't have this information in EXIF. All these commands are executed on the host machine:

Convert to CSV and lowercase all image names in the CSV file to match the photos' names which are lowercase:

cd /odm_data
wget https://raw.githubusercontent.com/wenzeslaus/jxl2csv/master/jxl2csv.py
python jxl2csv.py full.jxl full.csv
tr A-Z a-z < full.csv > full_lowercase.csv
Update EXIF with GPS coordinates, focal length, camera model. There will be some warnings, ignore them.
wget https://raw.githubusercontent.com/petrasovaa/write-EXIF-GPS/master/write_exif_GPS.py
python write_exif_GPS.py full_lowercase.csv
Warning: script write_exif_GPS.py is not general, focal length and camera model are hardcoded and must be changed for different cameras.

Our camera model is not in OpenSfM database yet, so you have to download the updated camera database file:

cd /odm_app/OpenDroneMap/src/OpenSfM/opensfm/data/
wget http://ncsu-osgeorel.github.io/uav-lidar-analytics-course/assignments/resources/sensor_data.json -O sensor_data.json
cd /odm_data

To georeference the DSM, we need to prepare a text file with each GCP on one line, where the numbers represent GCP X, GCP Y, GCP altitude, image row, image column, image name. For example:

636795.964 219156.17 105.06 1588 2066 DSC01861.jpg
Download the prepared GCP file here.
wget http://ncsu-osgeorel.github.io/uav-lidar-analytics-course/assignments/resources/gcp_odm.txt
Now we are ready to run OpenDroneMap!

Running OpenDroneMap

Run ODM on your host machine. We will use default parameters. To review parameters run:
/odm_app/OpenDroneMap/run.py --h
Now we launch the computation. We will keep default values, but we need to specify the path to file with GCPs.
cd /odm_data
/odm_app/OpenDroneMap/run.py --use-opensfm --odm_georeferencing-useGcp --odm_georeferencing-gcpFile gcp_odm.txt
By using he option --use-opensfm we select project OpenSfM as backend, which seems to be faster and producing better results.

Importing results

All results are stored in /odm_data/reconstruction-with-image-size-2400-results/. We are interested in the point cloud pointcloud_georef.laz. To import it to GRASS GIS, we will first convert it to .las file using LAStools installed already during ODM installation. Still on the host machine run:
cd /odm_data/reconstruction-with-image-size-2400-results/
/odm_app/OpenDroneMap/src/lastools/bin/las2las -i pointcloud_georef.laz -o pointcloud_georef.las
and then we use r.in.lidar to create a DSM by binning as we did in the previous assignment or v.surf.rst to interpolate a DSM. Use -o flag when importing into GRASS GIS ncspm location - the las file metadata show UTM, but the GCPs coordinates were in ncspm. We can also quickly view our results in plas.io (needs browser with WebGL support).