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

CLI --affine parameter has no effect #243

Closed
mstenta opened this issue Oct 7, 2024 · 4 comments
Closed

CLI --affine parameter has no effect #243

mstenta opened this issue Oct 7, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@mstenta
Copy link
Contributor

mstenta commented Oct 7, 2024

It seems that the --affine CLI parameter is not working as expected.

Expected behavior

According to the CLI help text for the --affine parameter:

Overwrites multiple parameters to optimize the stitching for scans and images captured by specialized devices.

The tutorial specifically outlines the parameters that should be overridden:

{'estimator': 'affine', 'wave_correct_kind': 'no', 'matcher_type': 'affine', 'adjuster': 'affine', 'warper_type': 'affine', 'compensator': 'no'}

Actual behavior

The CLI script does not explicitly override those parameters when --affine is used, and it explicitly sets them to non-affine defaults.

For example, the --matcher_type CLI parameter sets default=FeatureMatcher.DEFAULT_MATCHER, which is homography.

default=FeatureMatcher.DEFAULT_MATCHER,

Steps to reproduce

The following Docker commands (with any set of images) will create verbose output with 00_stitcher.txt files that show the actual parameters that are used.

With --affine:

Command: sudo docker run --rm -v ./:/data openstitching/stitch --affine --verbose ./*.jpg

Result: AffineStitcher(**{'medium_megapix': 0.6, 'detector': 'orb', 'nfeatures': 500, 'matcher_type': 'homography', 'range_width': -1, 'try_use_gpu': False, 'match_conf': None, 'confidence_threshold': 1, 'matches_graph_dot_file': None, 'estimator': 'homography', 'adjuster': 'ray', 'refinement_mask': 'xxxxx', 'wave_correct_kind': 'horiz', 'warper_type': 'spherical', 'low_megapix': 0.1, 'crop': True, 'compensator': 'gain_blocks', 'nr_feeds': 1, 'block_size': 32, 'finder': 'dp_color', 'final_megapix': -1, 'blender_type': 'multiband', 'blend_strength': 5, 'timelapse': 'no'})

Without --affine:

Command: sudo docker run --rm -v ./:/data openstitching/stitch --verbose ./*.jpg

Result 00_stitcher.txt:

Stitcher(**{'medium_megapix': 0.6, 'detector': 'orb', 'nfeatures': 500, 'matcher_type': 'homography', 'range_width': -1, 'try_use_gpu': False, 'match_conf': None, 'confidence_threshold': 1, 'matches_graph_dot_file': None, 'estimator': 'homography', 'adjuster': 'ray', 'refinement_mask': 'xxxxx', 'wave_correct_kind': 'horiz', 'warper_type': 'spherical', 'low_megapix': 0.1, 'crop': True, 'compensator': 'gain_blocks', 'nr_feeds': 1, 'block_size': 32, 'finder': 'dp_color', 'final_megapix': -1, 'blender_type': 'multiband', 'blend_strength': 5, 'timelapse': 'no'})

Cause

This is happening because the --affine parameter only affects which class is used (AffineStitcher() instead of Stitcher()), but it does not explicitly override the parameters that are passed into initialize_stitcher().

stitcher = AffineStitcher(**args_dict)

Solution

Perhaps before line 318 of cli/stitch.py all of the parameters that should be overridden for affine-mode can be reset to the appropriate values.

This would mean that if --affine is used, then the other parameters would have no effect (--estimator, --wave_correct_kind, --matcher_type, --adjuster, --warper_type, --compensator).

The other option is to still allow individual options to be overridden AFTER the --affine overrides are applied, but I feel like someone wants to do that they shouldn't use --affine.

Workaround

For now, if you need the effects of --affine, those parameters can be explicitly set on the command line like so:

--wave_correct_kind no --matcher_type affine --adjuster affine --warper_type affine --compensator no --estimator affine

@mstenta
Copy link
Contributor Author

mstenta commented Oct 7, 2024

Opened a PR that proposes a very simple (one line) fix: #244

@lukasalexanderweber
Copy link
Member

wow great catch and awesome issue with really much detail!

That means using --affine mode in the cli was never working :(

I thought that the cli only have those arguments in the args_dict that are actually used by the user.

Anyway, even then if the user passes in --affine --matcher_type homography the matcher_type should automatically be overwritten with affine as you shoud not mix the two models

Certain detailed settings of cv::Stitcher might not make sense. Especially you should not mix classes implementing affine model and classes implementing Homography model, as they work with different transformations.

@lukasalexanderweber
Copy link
Member

lukasalexanderweber commented Oct 8, 2024

This is the perfect explanation for #125, since its not affine stitching but homographic stitching with vertical wave correction

@lukasalexanderweber lukasalexanderweber added the bug Something isn't working label Oct 8, 2024
@lukasalexanderweber
Copy link
Member

closed with da14e49

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants