Skip to content

Fix stitching Python bindings (and one stitching_detailed.cpp bug)#22329

Merged
asmorkalov merged 1 commit intoopencv:4.xfrom
chinery:stitching-py-fixes
Oct 7, 2022
Merged

Fix stitching Python bindings (and one stitching_detailed.cpp bug)#22329
asmorkalov merged 1 commit intoopencv:4.xfrom
chinery:stitching-py-fixes

Conversation

@chinery
Copy link
Copy Markdown
Contributor

@chinery chinery commented Aug 1, 2022

Notes

This PR fixes two small issues in the header files for the stitching code, fixing two issues in Python and one minor one in the sample C++ code stitching_detailed.cpp.

  1. changes to BestOf2NearestRangeMatcher fixing BestOf2NearestRangeMatcher not working in Python or stitching_detailed.cpp #22315
    1. operator (called apply2 in Python) now has CV_WRAP_AS and CV_OUT to work correctly in Python
    2. the base class FeaturesMatcher version of this function is marked as virtual fixing a bug in stitching_detailed.cpp where the --rangewidth argument did not do anything, and BestOf2NearestRangeMatcher's version is marked as CV_OVERRIDE correspondingly
  2. The GraphCutSeamFinder masks argument is now correctly marked as CV_IN_OUT fixing GraphCutSeamFinders find() method returns None instead of masks #20945

I ran opencv_test_stitching and got no errors

[ PASSED ] 21 tests.

This is my first PR here so I hope I did everything correctly, please let me know if not!

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • (I think so!) The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • (N/A) There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • (N/A) The feature is well documented and sample code can be built with the project CMake

@chinery
Copy link
Copy Markdown
Contributor Author

chinery commented Aug 2, 2022

Just looking at the tests above, it looks like the macOS-ARM64 build just failed to clone the repo due a timeout, not sure why, but can someone resubmit that test? (Ironically, macOS-ARM64 is the one platform I did test locally, so I am confident it'll work given all the others did!)

@chinery
Copy link
Copy Markdown
Contributor Author

chinery commented Aug 3, 2022

The test seems to be failing because it is unable to clone opencv-extras from my personal GitHub, probably because I did not make any changes there and so didn't fork it? I have created a fork anyway with no changes to see if it passes when it reruns.

@asmorkalov
Copy link
Copy Markdown
Contributor

No, it's connectivity issue. I re-triggered the failed jobs.

@asmorkalov asmorkalov added the pr: needs test New functionality requires minimal tests set label Aug 5, 2022
@asmorkalov
Copy link
Copy Markdown
Contributor

@chinery Could you add test or at least python code snippet that reproduces the issue. Test data is required too.

@chinery
Copy link
Copy Markdown
Contributor Author

chinery commented Aug 5, 2022

@asmorkalov I'll add a C++ test for point 1ii. Is there a place I can add Python test code? Or should I just put the snippet here?

chinery added a commit to chinery/opencv that referenced this pull request Aug 5, 2022
Add tests for stitching, range_width matcher and graph cuts seam finder
@chinery
Copy link
Copy Markdown
Contributor Author

chinery commented Aug 5, 2022

Don't worry have found the Python tests and added some

@asmorkalov asmorkalov removed the pr: needs test New functionality requires minimal tests set label Aug 5, 2022
@asmorkalov
Copy link
Copy Markdown
Contributor

Thanks a lot for the provided test cases!

chinery added a commit to chinery/opencv that referenced this pull request Aug 5, 2022
chinery added a commit to chinery/opencv that referenced this pull request Aug 5, 2022
@chinery chinery force-pushed the stitching-py-fixes branch from e2c01c1 to bf402dd Compare August 5, 2022 14:12
@chinery
Copy link
Copy Markdown
Contributor Author

chinery commented Aug 5, 2022

The previous test failed due to some bad whitespace, I have just re-committed with that fixed

@chinery
Copy link
Copy Markdown
Contributor Author

chinery commented Aug 8, 2022

HI @asmorkalov sorry could you retrigger the tests, they just seemed to fail on formatting before which I've hopefully fixed.

@chinery
Copy link
Copy Markdown
Contributor Author

chinery commented Aug 26, 2022

Hi all, is there anything left to do before this can be approved? Thanks!

@chinery
Copy link
Copy Markdown
Contributor Author

chinery commented Sep 12, 2022

Hi @asmorkalov, @alalek, sorry for the extra mention, but could you take a look and see if there's anything outstanding for this pull request? Thanks.

@asmorkalov
Copy link
Copy Markdown
Contributor

Hello @chinery Thanks for the contribution! I apologize for the long wait. Too many PRs are in on-going state now.
On matchers:

  1. operator() and virtual methods. Original module design implements strategy like architecture. The base class implements non-virtual operator() and the operator implementation calls class specific method like match() or estimate(). So the C++ virtual works on the second step after base class operator(). It means that there is no need to add virtual to it. There is no bug in MotionEstimator design too.
  2. The second overload (apply2) was added later and violates the design pattern. I propose to fix the design issue in the following way:
  • Stay with the second operator() overload as non virtual method.
  • Extract its implementations as dedicated protected virtual methods as it's done for match
  • Export it to python and other languages with CV_WRAP_AS(apply2)

@asmorkalov asmorkalov self-requested a review September 12, 2022 13:17
@chinery
Copy link
Copy Markdown
Contributor Author

chinery commented Sep 13, 2022

Hello @chinery Thanks for the contribution! I apologize for the long wait. Too many PRs are in on-going state now. On matchers:

  1. operator() and virtual methods. Original module design implements strategy like architecture. The base class implements non-virtual operator() and the operator implementation calls class specific method like match() or estimate(). So the C++ virtual works on the second step after base class operator(). It means that there is no need to add virtual to it. There is no bug in MotionEstimator design too.
  2. The second overload (apply2) was added later and violates the design pattern. I propose to fix the design issue in the following way:
  • Stay with the second operator() overload as non virtual method.
  • Extract its implementations as dedicated protected virtual methods as it's done for match
  • Export it to python and other languages with CV_WRAP_AS(apply2)

No problem at all @asmorkalov.

I remember thinking that the existing "apply2" method seemed to violate the established pattern (though I could not find this philosophy documented anywhere, so it was tricky to be sure from the code alone). Your proposal makes sense to fix the inconsistency, I'll do that and report back here shortly.

One thing, could you clarify this comment?

There is no bug in MotionEstimator design too.

I don't believe I've touched any of the motion estimation code, but I may have simply forgotten something I mentioned prior!

@asmorkalov
Copy link
Copy Markdown
Contributor

It's my fault. Please do not mind MotionEstimator. It's from another PR.

@chinery
Copy link
Copy Markdown
Contributor Author

chinery commented Sep 13, 2022

No problem @asmorkalov!

I've just pushed the changes, so I think the design philosophy matches now (no pun intended). Thanks for the continued help and patience.

@asmorkalov
Copy link
Copy Markdown
Contributor

Looks good to me! Please squash commits and I'll merge it as single patch.

Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

chinery added a commit to chinery/opencv that referenced this pull request Sep 13, 2022
chinery added a commit to chinery/opencv that referenced this pull request Sep 13, 2022
chinery added a commit to chinery/opencv that referenced this pull request Sep 13, 2022
@chinery
Copy link
Copy Markdown
Contributor Author

chinery commented Sep 13, 2022

After some silly git errors I've now squashed the commits @asmorkalov, thanks again!

@asmorkalov asmorkalov self-assigned this Sep 13, 2022
@asmorkalov
Copy link
Copy Markdown
Contributor

@alalek Could you add exception to abi-complience checker for the API change. It safe for java, python, others.

@asmorkalov
Copy link
Copy Markdown
Contributor

@alalek friendly reminder.

@asmorkalov asmorkalov added the need-ci-update CI or Infra update required to merge PR label Sep 21, 2022
@asmorkalov asmorkalov merged commit 5cd0700 into opencv:4.x Oct 7, 2022
@alalek alalek mentioned this pull request Jan 8, 2023
a-sajjad72 pushed a commit to a-sajjad72/opencv that referenced this pull request Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants