diff --git a/copy_geo_exiftool.py b/copy_geo_exiftool.py index 03f114c..b93d8c9 100644 --- a/copy_geo_exiftool.py +++ b/copy_geo_exiftool.py @@ -4,32 +4,40 @@ import json def get_geolocation_with_exiftool(image_path): - command = ["exiftool", "-json", "-GPSLatitude", "-GPSLongitude", "-GPSAltitude", image_path] + command = ["exiftool", "-json", "-GPSLatitude", "-GPSLongitude", "-GPSAltitude", "-GPSLatitudeRef", "-GPSLongitudeRef", image_path] # Added reference tags process = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) output = process.stdout try: data = json.loads(output)[0] - return data.get('GPSLatitude'), data.get('GPSLongitude'), data.get('GPSAltitude') + return ( + data.get('GPSLatitude'), + data.get('GPSLongitude'), + data.get('GPSAltitude'), + data.get('GPSLatitudeRef'), # Extract references + data.get('GPSLongitudeRef') + ) except json.JSONDecodeError: - return None, None, None + return None, None, None, None, None # Return None for all values if there's an error -def write_geolocation_with_exiftool(dest_image, latitude, longitude, altitude): +def write_geolocation_with_exiftool(dest_image, latitude, longitude, altitude, GPSLatitudeRef, GPSLongitudeRef): command = [ "exiftool", - "-overwrite_original", # Modify in-place + "-overwrite_original", f"-GPSLatitude={latitude}", f"-GPSLongitude={longitude}", f"-GPSAltitude={altitude}", + f"-GPSLatitudeRef={GPSLatitudeRef}", # Added + f"-GPSLongitudeRef={GPSLongitudeRef}", # Added dest_image ] subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) def process_single_image(raw_image_path, mask_image_path): - lat, lon, alt = get_geolocation_with_exiftool(raw_image_path) + lat, lon, alt, lat_ref, lon_ref = get_geolocation_with_exiftool(raw_image_path) # Get references if lat and lon and alt: - write_geolocation_with_exiftool(mask_image_path, lat, lon, alt) + write_geolocation_with_exiftool(mask_image_path, lat, lon, alt, lat_ref, lon_ref) # Pass references print(f"Geolocation information copied from {raw_image_path} to {mask_image_path}.") else: print("No geolocation information found in the source image.") diff --git a/main.py b/main.py index 1cdea8c..4e6930d 100644 --- a/main.py +++ b/main.py @@ -46,7 +46,7 @@ def main(): call_in_conda_env("python copy_geolocation_crack.py") log_message("Convert overlay images to pointcloud. ") - call_in_conda_env("python overlay2pointcloud.py --damage_type 'crack'") + call_in_conda_env("python overlay2pointcloud.py --damage_type crack") if process_stain: # Run stain related processing @@ -57,10 +57,10 @@ def main(): call_in_conda_env("python stainoverlay.py") log_message("Copying geolocation info to stain overlay...") - call_in_conda_env("python copy_geolocation_stain.py") + call_in_conda_env("python3 copy_geolocation_stain.py") log_message("Convert overlay images to pointcloud. ") - call_in_conda_env("python overlay2pointcloud.py --damage_type stain") + call_in_conda_env("python3 overlay2pointcloud.py --damage_type stain") log_message("Script sequence completed.")