Select to view content in your preferred language

Methodology for Geotagging DJI FPV Video and Import into Drone2Map

1264
1
05-11-2022 01:02 PM
RyanWalter
New Contributor III

Hi all - I've been working on this for the better part of 3 days now and have finally come up with a methodology for importing video from the DJI FPV drone into Drone2Map for the purpose of creating orthomosaics and other 2D projects. I couldn't find any information or previous literature on a methodology to integrate DJI's FPV drone into the Drone2Map system, so I hope this can help the next person looking for an answer to this question. I'm sure there are better ways of doing what I'm about to detail, and if there are, please let me know. Also, if this methodology has some use for other drones, please let me know. 

Before I get started I wanted to lay out a couple of assumptions/caveats. This methodology has only been developed for converting video taken at a nadir-to-oblique angle into geotagged still images that can be imported into Drone2Map. It requires minimal comfort with command line interaction and python script editing, a couple of third party applications in addition to Drone2Map, and paying attention to your altitude and timings while in-flight (the DJI FPV altitude reading is consistently inaccurate and useless). I'm assuming that, for most people, imagery will be captured a constant height over flat(ish) ground. That could be an incorrect assumption, but it's one made in this summary. For this process to work, you must have the DJI FPV drone set to record SRT data. This is on by default, but can be toggled on in the system settings menu. This methodology also requires: VLC Media PlayerExif Tool, a script editing software (I use Visual Studio).

VLC Media Player can be found here: https://www.videolan.org/vlc/download-windows.html

Exif Tool here (download the Windows executable and install. Change application name from "exiftool(-k).exe" to "exiftool.exe" and then drop that into the C:\Windows directory): https://exiftool.org/ 

Visual Studio Code here: https://code.visualstudio.com/download 

With all of this ready to go, it's time to begin. First thing is first, create a working directory. For this example, I'll call it "C:\User\YOUR_NAME\Documents\FPV Geotagging". Move your data (video and .SRT) over from your microSD card, to this directory. Make copies of this data now, just in case. Head over to this site: https://djitelemetryoverlay.com/srt-viewer/. On the front page, hit "Load File(s)" and upload the .SRT file for the video of the flight you want to convert to geotagged imagery. Marvel at the incredibly cool visualization of your flight path and data. Download the telemetry data as a CSV. This will be a record of the GPS Lat/Lon/Altitude (if you trust that last one, I personally do not) data for each frame of the video. Save this in our working directory.

Open your FPV video in VLC Media Player. Open up the Tools menu and select Preferences. In the lower left corner of the Preferences window that just popped up will be a toggle to switch between simple and advanced preferences. Select advanced preferences. In the menu on the left, scroll down to the "Video" menu. Click the drop down menu to see all video preferences, and click on "Filters". The right half of this window should now list several filters with check boxes next to each. Check the one named "Scene video filter" (in my build of VLC, it is third from the top in the second column). With that filter selected, return to the scrollable menu on the left and click the drop down arrow next to the word "Filters". Scroll down and select "Scene filter". Change the preferences so that the image format is "JPG" and the directory path prefix is our working directory ("C:\User\YOUR_NAME\Documents\FPV Geotagging" in this case). Next, adjust the recording ratio according to your camera's frame rate and how many photos you want exported from this video. DJI FPV records at 60 frames per second, so I set the recording ratio to 60 to capture a photo every second of video. For more information on how this works and what recording ratio you should use, check out this great guide (https://www.vlchelp.com/automated-screenshots-interval/#:~:text=Expand%20further%2C%20Video%20%3E%20...). Click Save in the lower righthand corner and then close the VLC window. Reopen the video in VLC and it should start exporting a phot every second into our working directory. Check to make sure this is happening. If it is not, consult the previously linked resource. Each frame should be exported as an image named "scene00001.jpg", "scene00061.jpg", "scene00121.jpg", etc. The numbers following "scene" correlate to the frame in the video from which they were captured (i.e, "scene0001.jpg" is a JPG formatted image of the first frame of the video). With these saved in the directory, it's time to geotag the images. 

Open up Visual Studio Code, as well as the CSV we saved earlier. If you need to set up VS Code, do so now. There's lots of documentation for how to do so online. If you're using another code editing software, just ignore this part :).

Assuming you're using Microsoft Excel, return to the CSV, create a new column next to the "FRAMECNT" column called "File Name". Highlight the frame count values in the "FRAMECNT" column, right click, and select "Format cells". In the left hand menu, select "Special" and then "ZIP Code" under the "Type" column. This will add in leading zeros to our frame count. There are other ways to do this, I'm aware, and if you have a better method please post it. This is just a quick and dirty way of doing so. In the first cell below "File Name", build an expression to reconstruct the name of our file, in this case, we want "scene00001.jpg" to be in the first cell below "File Name", "scene00001.jpg" to be second, so on and so forth. Make sure you past over these/create a new column for these names as Values only. Create a new sheet within this CSV, and open a Windows File Explorer window. Navigate to the working directory. Sort all the files by name, and highlight all of the drone image files (and only the images). Holding shift, right click and select "Copy as path...". Return to Excel and our blank sheet. Paste the list of files. Create a new column, again called "File Name", and grab the file names from the tail end of the file paths we just pasted ("=RIGHT(A2,14)" should do the trick. Drag that all the way down. Make sure to copy and paste over this column as Values). Create five new columns called "LATITUDE", "LAT REF", "LONGTIUDE", "LON REF", and "ALTITUDE". Using an X or V lookup, return lat, long, and altitude values for each file, using the "File Name" columns as the reference point. In the Lat/Lon Ref columns, enter N/S or E/W, respectively (see: https://exiftool.org/faq.html#Q14 for an explanation on this). There might be better/easier/better explained ways of doing this. To look up how to do this, check out Microsoft's support pages on X and V lookups. My apologies for any confusion on this. The ultimate goal here is a list of the lat/long/alt values for each file, which can be accomplished following what I just laid out. Once this is done, save this tab as its own CSV in our working directory as "SRT_Telemtry.csv".

 

Returning to Visual Studio, paste in the following block:

 

 

 

import os
import csv

with open('F:/Drone Footage/05.10.2022/Frame_Geotagging_Data.csv','r') as file:
    reader=csv.DictReader(file)

    for lyrname in reader:
        picture_filename = lyrname['File Name']
        gps_latitude = lyrname['Latitude']
        gps_longitude = lyrname['Longitude']
        gps_altitude = '20'
        gps_lat_ref = lyrname['Lat Ref']
        gps_lon_ref = lyrname['Lon Ref']
        command_string = f'exiftool -GPSLatitude="{gps_latitude}" {picture_filename}'
        os.system(command_string)
        command_string = f'exiftool -GPSLatitudeRef="{gps_lat_ref}" {picture_filename}'
        os.system(command_string)
        command_string = f'exiftool -GPSLongitude="{gps_longitude}" {picture_filename}'
        os.system(command_string)
        command_string = f'exiftool -GPSLongitudeRef="{gps_lon_ref}" {picture_filename}'
        os.system(command_string)
        command_string = f'exiftool -GPSAltitude="{gps_altitude}" {picture_filename}'
        os.system(command_string)

 

 

 

 Change the file path to your own working directory (the string following the "open" command in line 3) and save this script to our working working directory as "batch_exif_writing.py". Open a command terminal and change your directory to the working directory ("cd C:\Users\YOUR_NAME\Documents\FPV Geotagging"). Enter "python batch_exif_writing.py" and hit enter. You should see a stream of "1 image has been updated" messages pour across your terminal window as all of your files are geotagged.

Once the script finishes running (it took my computer about 5 minutes), your images are now geotagged and can be loaded into Drone2Map! Anyways, I hope this guide helps someone out there looking to use the DJI FPV drone and Drone2Map. I'm still working through the imagery to clean up any artifacts/unwanted bits of imagery from the image capturing process. But that's a post for a different day. Please let me know if you have edits/suggestions/comments/criticisms to this process. I'm sure there are easier ways to do this, but this is what worked for me and I had to make in a vacuum. Thank you!

1 Reply
JonathanDandois
Occasional Contributor

OMG this is amazing @RyanWalter . gonna try this out and let you know how it goes!

0 Kudos