This is just an addendum to get location information at a frame level from aerial drone video for drone video analytics if the gps json is unavailable and the drone stamps the image with the information:
from PIL import Image
from PIL.ExifTags import TAGS, GPSTAGS
def get_exif_data(image_path):
try:
image = Image.open(image_path)
exif_data = {}
info = image._getexif()
if info:
for tag, value in info.items():
decoded = TAGS.get(tag, tag)
exif_data[decoded] = value
return exif_data
except Exception as e:
print(f"Error: {e}")
return None
def get_geotagging(exif_data):
if not exif_data:
return None
geotagging = {}
for key, value in exif_data.items():
if key == "GPSInfo":
for tag, val in value.items():
decoded = GPSTAGS.get(tag, tag)
geotagging[decoded] = val
return geotagging
def convert_to_degrees(value):
d, m, s = value
return d + (m / 60.0) + (s / 3600.0)
def get_lat_lon(geotagging):
lat = None
lon = None
if "GPSLatitude" in geotagging and "GPSLongitude" in geotagging:
lat = convert_to_degrees(geotagging["GPSLatitude"])
if geotagging["GPSLatitudeRef"] != "N":
lat = -lat
lon = convert_to_degrees(geotagging["GPSLongitude"])
if geotagging["GPSLongitudeRef"] != "E":
lon = -lon
return lat, lon
# Example usage:
image_path = "../../../skyquery-dataset/data/frames/main/013909.jpg" # Replace with your image path
exif_data = get_exif_data(image_path)
geotagging = get_geotagging(exif_data)
print("EXIF Data:", exif_data)
print("Geotagging:", geotagging)
if geotagging:
lat, lon = get_lat_lon(geotagging)
print("Latitude:", lat)
print("Longitude:", lon)
No comments:
Post a Comment