From 1df14ded247568d890be200b9588a234acbf0930 Mon Sep 17 00:00:00 2001 From: Robert Date: Wed, 30 Apr 2025 14:44:11 -0400 Subject: [PATCH] GPS Within 10 Feet checking... --- coordinates.py | 42 ++++++++++++++++++++++-------------------- dedup.py | 48 ++++++++++++++++++++++++++++++------------------ 2 files changed, 52 insertions(+), 38 deletions(-) diff --git a/coordinates.py b/coordinates.py index 8427a4f..71c94d4 100644 --- a/coordinates.py +++ b/coordinates.py @@ -1,6 +1,7 @@ from PIL import Image from PIL.ExifTags import TAGS, GPSTAGS import os +import math """ Copyright (c) 2025 by Robert Strutts @@ -78,33 +79,34 @@ def get_lat_lon(gps_info): import math -def haversine(lat1, lon1, lat2, lon2): +def haversine_distance_feet(coord1, coord2): """ - Calculate the great circle distance between two points - on the earth (specified in decimal degrees) - Returns distance in miles + Calculate the Haversine distance between two coordinates in feet. + Returns: + float: distance in feet """ - # Convert decimal degrees to radians - lat1, lon1, lat2, lon2 = map(math.radians, [lat1, lon1, lat2, lon2]) + # Earth radius in meters + R = 6371000 - # Haversine formula - dlon = lon2 - lon1 - dlat = lat2 - lat1 - a = math.sin(dlat/2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon/2)**2 - c = 2 * math.asin(math.sqrt(a)) + lat1, lon1 = math.radians(coord1[0]), math.radians(coord1[1]) + lat2, lon2 = math.radians(coord2[0]), math.radians(coord2[1]) - # Radius of earth in miles (3956 for miles, 6371 for kilometers) - r = 3956 - return c * r - -def are_within_one_mile(lat1, lon1, lat2, lon2): - distance = haversine(lat1, lon1, lat2, lon2) - return distance <= 1 + dlat = lat2 - lat1 + dlon = lon2 - lon1 + + a = (math.sin(dlat/2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon/2)**2) + c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a)) + + # Distance in meters + distance_meters = R * c + + # Convert to feet + return distance_meters * 3.28084 """ Example points: -point1 = (40.7128, -74.0060) # New York City -point2 = (40.7200, -74.0100) # About 0.5 miles from NYC +point1 = (40.7484, -73.9857) # Empire State Building coordinates (approximately) +point2 = (40.748405, -73.985685) # about 10 feet northeast of point1 """ def get_coordinates_from_image(image_path): diff --git a/dedup.py b/dedup.py index f42dd55..56a26cb 100644 --- a/dedup.py +++ b/dedup.py @@ -28,40 +28,52 @@ Processing time scales with area, so 4x downscale = ~16x faster initial alignmen Memory usage significantly reduced """ -within_one_mile_check = False +within_feet_check = True +withinFeet = 10 # < 10 feet +# Photo File Size Limits: too_small = 1024 # 1KB too_large = 10 * 1024 * 1024 # 10MB -def handle_GPS(location1, location2): - camera_info1, latitude1, longitude1 = location1 +def camera_check(camera_info1, camera_info2, diff_location = False): make1 = camera_info1['Make'] model1 = camera_info1['Model'] - - camera_info2, latitude2, longitude2 = location2 make2 = camera_info2['Make'] model2 = camera_info2['Model'] - - point1 = (latitude1, longitude1) - point2 = (latitude2, longitude2) - - if point1 == point2: - print("Images are both from same exact Location") - if make1 == make2 and model1 == model2: - print("Cameras are the same.") - print("✅Possible duplicate") - delibs.exit_timer(5) - elif coordinates.are_within_one_mile(*point1, *point2) and within_one_mile_check == True: + if diff_location == True: + print("Images are from different Locations") if make1 == make2 and model1 == model2: - print("Images are within one mile") print("Cameras are the same.") delibs.exit_timer(6) + else: + print("Different Cameras detected.") + print("👌Not a Duplicate") + delibs.exit_timer(0) else: - print("Images are from different Locations") if make1 != make2 or model1 != model2: print("Different Cameras detected.") print("👌Not a Duplicate") delibs.exit_timer(0) +def handle_GPS(location1, location2): + camera_info1, latitude1, longitude1 = location1 + camera_info2, latitude2, longitude2 = location2 + point1 = (latitude1, longitude1) + point2 = (latitude2, longitude2) + + if point1 == point2: + print("Images are both from same exact Location") + camera_check(camera_info1, camera_info2) + elif within_feet_check == True: + feet = coordinates.haversine_distance_feet(point1, point2) + print(f"Images distance in feet: {feet:.2f}") + if feet < withinFeet: + print(f"With in requirements of {withinFeet}") + camera_check(camera_info1, camera_info2) + else: + camera_check(camera_info1, camera_info2, True) + else: + camera_check(camera_info1, camera_info2, True) + def is_module_imported(module_name): return module_name in sys.modules