Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix gui #87

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ config/cameras_test.yaml
.vscode/
*.~lock*

# Pycharm
.idea

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
32 changes: 25 additions & 7 deletions src/deep_image_matching/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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']}"
Expand Down
21 changes: 8 additions & 13 deletions src/deep_image_matching/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 7 additions & 4 deletions src/deep_image_matching/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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",
Expand Down Expand Up @@ -146,12 +145,16 @@ def parse_cli() -> dict:
)
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.config_file = gui_out["config_file"]
args.extractor = gui_out["extractor"]
args.strategy = gui_out["strategy"]
args.pairs = gui_out["pair_file"]
args.overlap = gui_out["image_overlap"]
Expand Down
Loading