From c1261fd5ed36a20e78d13d27b2fd3867fc28d35f Mon Sep 17 00:00:00 2001 From: christopher schicho Date: Tue, 26 Nov 2024 18:29:02 +0100 Subject: [PATCH 1/2] fix gui --- .gitignore | 3 +++ src/deep_image_matching/config.py | 32 ++++++++++++++++++++++++------- src/deep_image_matching/gui.py | 21 ++++++++------------ src/deep_image_matching/parser.py | 11 ++++++++--- 4 files changed, 44 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index d5f21bc8..6f3219a2 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,9 @@ config/cameras_test.yaml .vscode/ *.~lock* +# Pycharm +.idea + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/src/deep_image_matching/config.py b/src/deep_image_matching/config.py index 93fdd345..f3494b8f 100644 --- a/src/deep_image_matching/config.py +++ b/src/deep_image_matching/config.py @@ -285,14 +285,21 @@ def __init__(self, args: dict): Args: args (dict): The input arguments provided by the user. """ + is_gui = args["gui"] is not None and args["gui"] + # Parse input arguments general = self.parse_general_config(args) # Build configuration dictionary self.cfg["general"] = {**conf_general, **general} - features_config = self.get_config(args["pipeline"]) - self.cfg["extractor"] = features_config["extractor"] - self.cfg["matcher"] = features_config["matcher"] + + if is_gui: + self.cfg["extractor"] = args["extractor"] + self.cfg["matcher"] = args["matcher"] + else: + features_config = self.get_config(args["pipeline"]) + self.cfg["extractor"] = features_config["extractor"] + self.cfg["matcher"] = features_config["matcher"] # If the user has provided a configuration file, update the configuration if "config_file" in args and args["config_file"] is not None: @@ -367,6 +374,8 @@ def parse_general_config(input_args: dict) -> dict: """ args = {**Config.default_cli_opts, **input_args} + is_gui = args["gui"] is not None and args["gui"] + # Check that at least one of the two options is provided if args["images"] is None and args["dir"] is None: raise ValueError( @@ -429,17 +438,26 @@ def parse_general_config(input_args: dict) -> dict: args["outs"].mkdir(parents=True, exist_ok=True) # Check extraction and matching configuration - if args["pipeline"] is None or args["pipeline"] not in confs: + if not is_gui and (args["pipeline"] is None or args["pipeline"] not in confs): raise ValueError( "Invalid config. --pipeline option is required and must be a valid pipeline. Check --help for details" ) - pipeline = args["pipeline"] - extractor = confs[pipeline]["extractor"]["name"] + + if is_gui: + extractor = args["extractor"]["name"] + else: + extractor = confs[args["pipeline"]]["extractor"]["name"] + if extractor not in opt_zoo["extractors"]: raise ValueError( f"Invalid extractor option: {extractor}. Valid options are: {opt_zoo['extractors']}" ) - matcher = confs[pipeline]["matcher"]["name"] + + if is_gui: + matcher = args["matcher"]["name"] + else: + matcher = confs[args["pipeline"]]["matcher"]["name"] + if matcher not in opt_zoo["matchers"]: raise ValueError( f"Invalid matcher option: {matcher}. Valid options are: {opt_zoo['matchers']}" diff --git a/src/deep_image_matching/gui.py b/src/deep_image_matching/gui.py index ec2c7b26..6202733a 100644 --- a/src/deep_image_matching/gui.py +++ b/src/deep_image_matching/gui.py @@ -69,30 +69,25 @@ def __init__(self, master): # state = "normal" if self.use_custom.get() else "disabled" # self.pair_file["state"] = state - def on_submit(self): - args = { + def __get_args(self): + return { "image_dir": Path(self.image_dir.get()), "out_dir": Path(self.out_dir.get()), - "config": self.config.get(), + "extractor": confs[self.config.get()]["extractor"], + "matcher": confs[self.config.get()]["matcher"], "strategy": self.strategy.get(), "pair_file": self.pair_file.get(), "image_overlap": self.overlap.get(), "upright": self.use_custom.get(), } - pprint(args) + def on_submit(self): + args = self.__get_args() + pprint(args) self.master.quit() def get_values(self): - args = { - "image_dir": Path(self.image_dir.get()), - "out_dir": Path(self.out_dir.get()), - "config": self.config.get(), - "strategy": self.strategy.get(), - "pair_file": self.pair_file.get(), - "image_overlap": self.overlap.get(), - "upright": self.use_custom.get(), - } + args = self.__get_args() if not args["image_dir"].exists() or not args["image_dir"].is_dir(): msg = f"Directory {args['image_dir']} does not exist" diff --git a/src/deep_image_matching/parser.py b/src/deep_image_matching/parser.py index 389b0d4f..4a3bf558 100644 --- a/src/deep_image_matching/parser.py +++ b/src/deep_image_matching/parser.py @@ -17,7 +17,7 @@ def parse_cli() -> dict: "-d", "--dir", type=str, - help="Project directoryt, containing a folder 'images', in which all the images are present and where the results will be saved.", + help="Project directory, containing a folder 'images', in which all the images are present and where the results will be saved.", default=None, ) parser.add_argument( @@ -38,9 +38,8 @@ def parse_cli() -> dict: "-p", "--pipeline", type=str, - help="Define the pipeline (combination of local feature extractor and matcher) to use for the matching.", + help="Define the pipeline (combination of local feature extractor and matcher) to use for the matching. MUST be provided if not using the GUI", choices=Config.get_pipelines(), - required=True, ) parser.add_argument( "-c", @@ -143,14 +142,20 @@ def parse_cli() -> dict: "--camera_options", help="Path to camera options yaml file, e.g. config/cameras.yaml", default="./config/cameras.yaml", + required=True, ) args = parser.parse_args() + if not args.gui and args.pipeline is None: + parser.error("without --gui, you must specify -p/--pipeline") + if args.gui is True: gui_out = gui() + args.gui = True args.images = gui_out["image_dir"] args.outs = gui_out["out_dir"] args.matcher = gui_out["matcher"] + args.extractor = gui_out["extractor"] args.config_file = gui_out["config_file"] args.strategy = gui_out["strategy"] args.pairs = gui_out["pair_file"] From 8f23d00e4142a7df44e545266ead673c6faa2c15 Mon Sep 17 00:00:00 2001 From: christopher schicho Date: Sun, 1 Dec 2024 17:46:17 +0100 Subject: [PATCH 2/2] fix gui --- src/deep_image_matching/parser.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/deep_image_matching/parser.py b/src/deep_image_matching/parser.py index 4a3bf558..44ba6ef4 100644 --- a/src/deep_image_matching/parser.py +++ b/src/deep_image_matching/parser.py @@ -142,7 +142,6 @@ def parse_cli() -> dict: "--camera_options", help="Path to camera options yaml file, e.g. config/cameras.yaml", default="./config/cameras.yaml", - required=True, ) args = parser.parse_args() @@ -156,7 +155,6 @@ def parse_cli() -> dict: args.outs = gui_out["out_dir"] args.matcher = gui_out["matcher"] args.extractor = gui_out["extractor"] - args.config_file = gui_out["config_file"] args.strategy = gui_out["strategy"] args.pairs = gui_out["pair_file"] args.overlap = gui_out["image_overlap"]