The previous posts explained how to leverage scale resolution of known vehicles to compute distances between landmarks given by their bounding boxes in aerial drone images but that is not the only way to calculate distance. With the information that aerial drone images are zoom in images of well-known mapping services images of known cities and urban environments, specifically in North America, the images can be analyzed with automation for determining culture, season, economic and regional styles to associate with a latitude and longitude. Even if it is not an exact match, an approximation to the city in which the aerial image was shot by the drone can help in narrowing down the suburb in which drone was moving. For example, the following a code enables a machine to understand which city the drone was flying over when a frame captured from its video is analyzed.
from geospyer import GeoSpy
import os
gemini_api_key = os.getenv("GEMINI_API_KEY").strip('"')
def get_nearest_latitude_longitude(image_path="frame23.jpg"):
# Initialize GeoSpy with your Gemini API key
geospy = GeoSpy(api_key=gemini_api_key)
# Analyze the image
result = geospy.locate(image_path=image_path)
# Check for errors
if "error" in result:
print(f"Error: {result['error']}")
else:
# Extract location info
if "locations" in result and result["locations"]:
location = result["locations"][0]
lat = location["coordinates"]["latitude"]
lon = location["coordinates"]["longitude"]
print(f"Estimated Coordinates: Latitude = {lat}, Longitude = {lon}")
# Optional: Open in Google Maps
# import webbrowser
maps_url = f"https://www.google.com/maps?q={lat},{lon}"
print(maps_url)
#webbrowser.open(maps_url)
return lat, lon
else:
print("No location data found.")
return None, None
print(get_nearest_latitude_longitude())
# output:
# Estimated Coordinates: Latitude = 42.3736, Longitude = -71.1097
# https://www.google.com/maps?q=42.3736,-71.1097
# (42.3736, -71.1097)
And as with earlier capabilities, such modular functions can be easily included in the list of function tools to augment agentic retrieval on the analysis side of the aerial drone image processing pipeline.
No comments:
Post a Comment