-
-
Save TN-1/30bfbb6a74b644e974ebd7ab9cc0248d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# EXIFFixer for DJI Spark | |
# Takes in an exported csv flight log from Airdata UAV and a list of photos and using a few assumptions updates | |
# the location data in EXIF to be much more accurate. Because fuck DJI. | |
# Assumptions: An orded list of image names is in chronological order to photos taken in the flight log, and no images are missing. | |
# IE: There needs to be a 1-1 relationship between images listed and images present in the flight log. | |
from exif import Image | |
from csv import reader | |
# Decimal degrees to DMS, from Stackoverflow <3 | |
def decdeg2dms(dd): | |
dd = float(dd) | |
is_positive = dd >= 0 | |
dd = abs(dd) | |
minutes, seconds = divmod(dd * 3600, 60) | |
degrees, minutes = divmod(minutes, 60) | |
#degrees = degrees if is_positive else -degrees ####Lock to positive numbers since it doesnt affect our case. | |
return (degrees, minutes, seconds) | |
# Setup variables | |
data = [] | |
dataClean = [] | |
images = [] | |
imageNames = ['DJI_1731.JPG', 'DJI_1734.JPG', 'DJI_1737.JPG', 'DJI_1740.JPG', 'DJI_1743.JPG', 'DJI_1746.JPG', 'DJI_1749.JPG', 'DJI_1752.JPG', 'DJI_1755.JPG', | |
'DJI_1732.JPG', 'DJI_1735.JPG', 'DJI_1738.JPG', 'DJI_1741.JPG', 'DJI_1744.JPG', 'DJI_1747.JPG', 'DJI_1750.JPG', 'DJI_1753.JPG', 'DJI_1733.JPG', | |
'DJI_1736.JPG', 'DJI_1739.JPG', 'DJI_1742.JPG', 'DJI_1745.JPG', 'DJI_1748.JPG', 'DJI_1751.JPG', 'DJI_1754.JPG'] | |
imageNames.sort() | |
# Load CSV into a list of lists | |
with open('input.csv', 'r') as read_obj: | |
csv_reader = reader(read_obj) | |
data = list(csv_reader) | |
data.pop(0) #Get rid of column headers | |
# Only keep the indexs with images | |
for i, row in enumerate(data): | |
if row[24] == '1': | |
dataClean.insert(i, row) | |
# Load images to update EXIF | |
for i, imageName in enumerate(imageNames): | |
with open(imageName, "rb") as image: | |
images.insert(i, Image(image)) | |
# Go through all images, find the correct location data and update | |
# GPS Information lat:data[i][2] long:data[i][3] | |
# Time data[i][1] | |
for i, image in enumerate(images): | |
image.gps_latitude = decdeg2dms(data[i][2]) | |
image.gps_longitude = decdeg2dms(data[i][3]) | |
print(f"{i} {decdeg2dms(data[i][2])} {decdeg2dms(data[i][3])}") | |
print(f"{i} {image.gps_latitude} {image.gps_latitude_ref} {image.gps_longitude} {image.gps_longitude_ref}") | |
# Save images | |
for i, imageName in enumerate(imageNames): | |
with open(imageName, 'wb') as image: | |
image.write(images[i].get_file()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment