This is a sample to illustrate geolocation verification in aerial images:
import cv2
import numpy as np
import requests
# Function to detect and extract features from the aerial image
def extract_features(image_path):
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
orb = cv2.ORB_create()
keypoints, descriptors = orb.detectAndCompute(image, None)
return keypoints, descriptors, image
# Function to match features between images
def match_features(descriptors1, descriptors2):
matcher = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
matches = matcher.match(descriptors1, descriptors2)
matches = sorted(matches, key=lambda x: x.distance) # Sort by match quality
return matches
# Function to get GPS coordinates using Google Maps API
def get_geolocation(image_name, api_key):
url = f"https://maps.googleapis.com/maps/api/geocode/json?address={image_name}&key={api_key}"
response = requests.get(url)
data = response.json()
if data["status"] == "OK":
location = data["results"][0]["geometry"]["location"]
return location["lat"], location["lng"]
return None
# Paths to images
aerial_image_path = "aerial_landmark.jpg"
reference_image_path = "reference_satellite.jpg"
# Extract features from both images
keypoints1, descriptors1, image1 = extract_features(aerial_image_path)
keypoints2, descriptors2, image2 = extract_features(reference_image_path)
# Match features
matches = match_features(descriptors1, descriptors2)
# Draw matches
output_image = cv2.drawMatches(image1, keypoints1, image2, keypoints2, matches[:50], None, flags=cv2.DrawMatchesFlags_NOT_DRAW_SINGLE_POINTS)
# Display results
cv2.imshow("Feature Matching", output_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
# Perform geolocation verification
api_key = "YOUR_GOOGLE_MAPS_API_KEY" # Replace with your API key
location = get_geolocation("Hoover Tower, Stanford University", api_key)
if location:
print(f"Verified Landmark Coordinates: Latitude {location[0]}, Longitude {location[1]}")
else:
print("Geolocation verification failed!")
No comments:
Post a Comment