Added GPS Coordinates checking.

main
Robert 8 months ago
parent b8eb3c8fce
commit 93670142fb
  1. 76
      coordinates.py
  2. 18
      dedup.py
  3. 4
      get_dups.bat
  4. 4
      get_dups.sh

@ -0,0 +1,76 @@
from PIL import Image
from PIL.ExifTags import TAGS, GPSTAGS
import os
def get_exif_data(image_path):
"""Get EXIF data from image file"""
try:
with Image.open(image_path) as img:
exif_data = img._getexif()
if exif_data is not None:
return {TAGS.get(tag, tag): value for tag, value in exif_data.items()}
except (AttributeError, IOError, KeyError, IndexError) as e:
print(f"Error reading EXIF data: {e}")
return None
def get_gps_info(exif_data):
"""Extract GPS information from EXIF data"""
if not exif_data or 'GPSInfo' not in exif_data:
return None
gps_info = {}
for key in exif_data['GPSInfo'].keys():
decode = GPSTAGS.get(key, key)
gps_info[decode] = exif_data['GPSInfo'][key]
return gps_info
def convert_to_degrees(value):
"""Convert GPS coordinates stored in EXIF to degrees in decimal format"""
d, m, s = value
return d + (m / 60.0) + (s / 3600.0)
def get_lat_lon(gps_info):
"""Get latitude and longitude from GPSInfo dictionary"""
if not gps_info:
return None, None
try:
lat_ref = gps_info.get('GPSLatitudeRef', 'N')
lat = gps_info.get('GPSLatitude')
lon_ref = gps_info.get('GPSLongitudeRef', 'E')
lon = gps_info.get('GPSLongitude')
if lat and lon:
lat_degrees = convert_to_degrees(lat)
if lat_ref == 'S':
lat_degrees = -lat_degrees
lon_degrees = convert_to_degrees(lon)
if lon_ref == 'W':
lon_degrees = -lon_degrees
return lat_degrees, lon_degrees
except (TypeError, AttributeError) as e:
print(f"Error converting coordinates: {e}")
return None, None
def get_coordinates_from_image(image_path):
"""Main function to get coordinates from image file"""
exif_data = get_exif_data(image_path)
if not exif_data:
print("No EXIF data found in image.")
return None
gps_info = get_gps_info(exif_data)
if not gps_info:
print("No GPS information found in EXIF data.")
return None
latitude, longitude = get_lat_lon(gps_info)
if latitude is not None and longitude is not None:
return (latitude, longitude)
else:
print("Could not extract valid coordinates.")
return None

@ -2,6 +2,8 @@ import sys
import cv2
# My Custom Library called delibs.py
import delibs
# coordinates is an OPTIONAL module!!!!!!!!! Feel free to commit it out.
import coordinates
"""
Copyright 2025 - Robert Strutts MIT License
@ -25,6 +27,9 @@ Processing time scales with area, so 4x downscale = ~16x faster initial alignmen
Memory usage significantly reduced
"""
def is_module_imported(module_name):
return module_name in sys.modules
def main():
if len(sys.argv) < 3:
print("Usage: python3 dedup.py file1.jpg file2.jpg")
@ -44,7 +49,18 @@ def main():
print("No transformation needed")
delibs.exit_timer(1)
else:
print("Done hashing...")
print("Done hashing...")
if is_module_imported('coordinates'):
print("Using Coordiantes module")
coordinates1 = coordinates.get_coordinates_from_image(file1)
if coordinates1 != None:
coordinates2 = coordinates.get_coordinates_from_image(file2)
if coordinates1 == coordinates2:
print("Images are both from same Location")
delibs.exit_timer(5)
else:
print("Not using Coordiantes module")
with delibs.Timer("Loading Images"):
# Load large images

@ -44,6 +44,10 @@ for /l %%i in (1,1,%count%) do (
echo %~1\!outer_image!>> alike.txt
goto :break_inner
)
if !errorlevel! equ 5 (
echo %~1\!outer_image!>> sameGPS.txt
goto :break_inner
)
if !errorlevel! equ 8 (
echo %~1\!outer_image!>> invalid.txt
goto :break_inner

@ -39,6 +39,10 @@ for ((i = 0; i < ${#images[@]}; i++)); do
echo "$1/$outer_image # $inner_image" >> alike.txt
break # No need to check more once found close match to duplicate
fi
if [ $exit_code -eq 5 ]; then
echo "$1/$outer_image # $inner_image" >> sameGPS.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

Loading…
Cancel
Save