3

I have a drone that I used to make a flight movie, and I am going to use this footage to build a DEM (digital elevation model) of the topography I was filming. I can extract frames from the movie easily enough, but the method (ffmpeg) does not give these frames the lat-lon-elev-etc information necessary to reliably build the DEM. All this data is available in a .csv file stored in the drone flight control app, which I have downloaded.

I want to extract from this .csv file all the columns of navigational data. I can do this using awk. Then I want to write a script that will attach the navigational data from a certain timestamp in the flightpath to a corresponding still frame extracted from the movie (at the same timestamp). I can use exiftool for attaching GPS data to an image, but being quite new to shell scripting I cannot get my current nested loop to work.

Currently, my script writes all lines from the .csv file to every picture in the folder. Instead, I want to write line1 (lat-lon-elev-etc) to photo1, line2 to photo2, and so on. I feel I should be able to fix this, but can't crack it: any help very welcome!

# Using awk, extract the relevant columns from the flightpath dataset
awk -F, '{print $1,$2,$3,$7,$15,$22,$23 }' test.csv > test2.csv

# Read through .csv file line-by-line
# Make variables that can be commanded
while IFS=" " read -r latitude longitude altitude time compHeading gimbHeading gimbPitch
do

# exiftool can now command these variables
# write longitude and latitude to some photograph
    for photo in *.png; do
    exiftool -GPSLongitude="$longitude"  -GPSLatitude="$latitude" *.png
    done

# Following line tells bash which textfile to draw data from
done < test2.csv
  • 1
    You may also want to take a look at gpscorrelate (you'll still need to add EXIF timestamps to the images first). PS: Elevation from a typical GPS receiver has a fair bit of error, consider adding a air pressure sensor altimeter... – derobert Feb 10 '17 at 14:59
  • Is the *.png at the end of the exiftool command line intentional, or should that be "$photo"? Does the original CSV file contain any information that could be used to pair the data with the photo? – Kusalananda Feb 10 '17 at 15:03
  • @Kusalananda, yes, that's a typo-- it should be "$photo" – brendanvolc Feb 13 '17 at 9:39
3

If you have the same number of photos as there are lines in the CSV file, then you can use a simple for loop:

for photo in *.png; do
  IFS=" " read -r latitude longitude altitude time compHeading gimbHeading gimbPitch
  exiftool -GPSLongitude="$longitude"  -GPSLatitude="$latitude" "$photo"
done < test2.csv

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.