From dba2888ae7804a4995662e2e0115e273d605c72b Mon Sep 17 00:00:00 2001 From: Bo Shang Date: Thu, 29 Feb 2024 22:45:04 -0500 Subject: [PATCH] docker works; GPSLatitudeRef tag GPSLongitudeRef tag missing --- main.py | 6 +++++ overlay2pointcloud.py | 58 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 overlay2pointcloud.py diff --git a/main.py b/main.py index 1099f0e..1cdea8c 100644 --- a/main.py +++ b/main.py @@ -44,6 +44,9 @@ def main(): log_message("Copying geolocation info to crack overlay...") 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'") if process_stain: # Run stain related processing @@ -56,6 +59,9 @@ def main(): log_message("Copying geolocation info to stain overlay...") call_in_conda_env("python copy_geolocation_stain.py") + log_message("Convert overlay images to pointcloud. ") + call_in_conda_env("python overlay2pointcloud.py --damage_type stain") + log_message("Script sequence completed.") if __name__ == "__main__": diff --git a/overlay2pointcloud.py b/overlay2pointcloud.py new file mode 100644 index 0000000..16f1621 --- /dev/null +++ b/overlay2pointcloud.py @@ -0,0 +1,58 @@ +import argparse +import subprocess +import configparser +import os + +def remove_image_part(path): + """Removes the 'images' part at the end of a given path. + + Args: + path (str): The original file system path. + + Returns: + str: The modified path without the 'images' segment. + """ + + parts = path.split(os.sep) # Split the path using the OS-specific separator + + # Handle potential scenarios: + if parts[-1] == "images": # 'images' is the last segment + parts = parts[:-1] + elif parts[-2] == "images": # 'images' is the second-to-last segment + parts = parts[:-2] + else: + print(f"Warning: 'images' directory not found in the expected location within the path '{path}'") + + return os.sep.join(parts) +def run_odm(damage_type): + """Executes the OpenDroneMap command with a project path based on damage type. + + Args: + damage_type (str): The type of damage (either 'crack' or 'stain'). + """ + + config = configparser.ConfigParser() + config.read('config.ini') # Read your config file + + if damage_type == 'crack': + project_path = config['CrackOverlay']['overlay_directory'] + elif damage_type == 'stain': + project_path = config['StainOverlay']['overlay_directory'] + else: + raise ValueError("Invalid damage_type. Must be 'crack' or 'stain'.") + + command = [ + "docker", "run", "-ti", "--rm", + "-v", f"{remove_image_part(project_path)}:/datasets/code", + "opendronemap/odm", + "--project-path", "/datasets" + ] + subprocess.run(command, check=True) + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description="Run OpenDroneMap with damage-specific overlays.") + parser.add_argument("--damage_type", choices=['crack', 'stain'], required=True, help="Type of damage: crack or stain") # Optional argument + args = parser.parse_args() + + + run_odm(args.damage_type)