-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
BestOf2NearestRangeMatcher not working in Python or stitching_detailed.cpp #22315
Description
System information (version)
- OpenCV => 4.6.0
- Operating System / Platform => MacOS
- Compiler => clang/Python
Detailed description
When calling BestOf2NearestRangeMatcher from Python with a range_width of 1, I still get matches between images that are not adjacent going by their index with non-zero confidence. In fact, changing the range_width value has no effect.
After downloading the source and running stitching_detailed.cpp I found the same issue.
Steps to reproduce
in Python:
#... get features from a feature detector
range = 1
matcher = cv2.detail_BestOf2NearestRangeMatcher(range)
pairwise_matches = matcher.apply2(features)
print([(match.src_img_idx, match.dst_img_idx, match.confidence) for match in pairwise_matches])for C++, run stitching_detailed.cpp with --rangewidth set to 1, and investigate the matches, e.g. add this to line 515
for (auto match : pairwise_matches) {
cout << match.src_img_idx << "," << match.dst_img_idx << ": " << match.confidence << endl;
}Expected: match confidences should mostly be zero except when abs(src_idx - dst_idx) == 1
Actual: match confidences are unchanged from when range_width = -1
Potential fix!
I think the issue in the C++ code is simply that the function is not marked as virtual, but is being called from a Ptr<FeaturesMatcher> in stitching_detailed.cpp.
If you make the following change in matchers.hpp:140:
CV_WRAP_AS(apply2) void operator ()(const ...
becomes
CV_WRAP_AS(apply2) virtual void operator ()(const ...
then stitching_detailed.cpp works as expected.
(Probably a good idea to change matchers.hpp:127 similarly)
I'd be happy to open a Pull Request for this fix. However, the stitching test suite does not run nicely on my M1 Mac and I haven't put much effort into fixing that yet.
I'm not sure why this polymorphism issue would affect Python where you call cv2.detail_BestOf2NearestRangeMatcher directly. Perhaps someone with more knowledge of how the Python to OpenCV layer works could help there.
Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues,
forum.opencv.org, Stack Overflow, etc and have not found any solution - I updated to the latest OpenCV version and the issue is still there
- There is reproducer code and related data files: videos, images, onnx, etc