diff --git a/coordinates.py b/coordinates.py index 12523bb..8427a4f 100644 --- a/coordinates.py +++ b/coordinates.py @@ -18,6 +18,21 @@ def get_exif_data(image_path): print(f"Error reading EXIF data: {e}") return None +def get_camera_info(exif): + if not exif: + return None + + camera_info = { + 'Make': exif.get('Make', 'Unknown'), + 'Model': exif.get('Model', 'Unknown') + } + + # Some cameras store model in 'Camera Model Name' instead + if camera_info['Model'] == 'Unknown': + camera_info['Model'] = exif.get('Camera Model Name', 'Unknown') + + return camera_info + def get_gps_info(exif_data): """Extract GPS information from EXIF data""" if not exif_data or 'GPSInfo' not in exif_data: @@ -60,6 +75,37 @@ def get_lat_lon(gps_info): print(f"Error converting coordinates: {e}") return None, None + +import math + +def haversine(lat1, lon1, lat2, lon2): + """ + Calculate the great circle distance between two points + on the earth (specified in decimal degrees) + Returns distance in miles + """ + # Convert decimal degrees to radians + lat1, lon1, lat2, lon2 = map(math.radians, [lat1, lon1, lat2, lon2]) + + # 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)) + + # 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 + +""" +Example points: +point1 = (40.7128, -74.0060) # New York City +point2 = (40.7200, -74.0100) # About 0.5 miles from NYC +""" def get_coordinates_from_image(image_path): """Main function to get coordinates from image file""" @@ -73,9 +119,11 @@ def get_coordinates_from_image(image_path): print("No GPS information found in EXIF data.") return None + camera_info = get_camera_info(exif_data) + latitude, longitude = get_lat_lon(gps_info) if latitude is not None and longitude is not None: - return (latitude, longitude) + return (camera_info, latitude, longitude) else: print("Could not extract valid coordinates.") return None diff --git a/dedup.py b/dedup.py index a02a348..fc135d1 100644 --- a/dedup.py +++ b/dedup.py @@ -29,14 +29,34 @@ Memory usage significantly reduced """ def handle_GPS(location1, location2): - if location1 == location2: + camera_info1, latitude1, longitude1 = location1 + 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") print("✅Possible duplicate") - delibs.exit_timer(5) + if make1 == make2 and model1 == model2: + print("Cameras are the same.") + delibs.exit_timer(5) +# elif coordinates.are_within_one_mile(*point1, *point2): +# if make1 == make2 and model1 == model2: +# print("Images are within one mile") +# print("Cameras are the same.") +# delibs.exit_timer(6) else: print("Images are from different Locations") print("👌Not a Duplicate") - delibs.exit_timer(0) + if make1 != make2 and model1 != model2: + print("Different Cameras detected.") + delibs.exit_timer(0) def is_module_imported(module_name): return module_name in sys.modules @@ -67,7 +87,8 @@ def main(): coordinates1 = coordinates.get_coordinates_from_image(file1) if coordinates1 != None: coordinates2 = coordinates.get_coordinates_from_image(file2) - handle_GPS(coordinates1, coordinates2) + if coordinates2 != None: + handle_GPS(coordinates1, coordinates2) else: print("Not using Coordinates module") diff --git a/get_dups.bat b/get_dups.bat index 6103e6c..3f9a0a4 100644 --- a/get_dups.bat +++ b/get_dups.bat @@ -50,6 +50,11 @@ for /l %%i in (1,1,%count%) do ( echo %~1\!outer_image!>> sameGPS.txt goto :break_inner ) + if !errorlevel! equ 5 ( + echo %~1\!outer_image!>> sameGPSmile.txt + goto :break_inner + ) + if !errorlevel! equ 8 ( echo %~1\!outer_image!>> invalid.txt goto :break_inner diff --git a/get_dups.sh b/get_dups.sh index 6d30a0b..a49f73e 100755 --- a/get_dups.sh +++ b/get_dups.sh @@ -44,6 +44,11 @@ for ((i = 0; i < ${#images[@]}; i++)); do echo "$1/$outer_image # $inner_image" >> sameGPS.txt break # No need to check more once found matching GPS image fi + if [ $exit_code -eq 6 ]; then + echo "$1/$outer_image # $inner_image" >> sameGPSmile.txt + break # No need to check more once found matching GPS image + fi + if [ $exit_code -eq 8 ]; then echo "$1/$outer_image # $inner_image" >> invalid.txt break # No need to check more once found bad image