0
0
mirror of https://github.com/opencv/opencv.git synced 2026-01-18 17:21:42 +01:00

Merge pull request #26366 from shyama7004:fix-orb.cpp

Fix ORB inconsistency for masks with values 255 and 1. #26366

### Pull Request Readiness Checklist

The PR fixes : [25974](https://github.com/opencv/opencv/issues/25974)

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

- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Skreg
2025-12-09 17:01:53 +05:30
committed by GitHub
parent 9a9ae12475
commit 2bf4f5c151
2 changed files with 33 additions and 2 deletions

View File

@@ -1036,7 +1036,11 @@ void ORB_Impl::detectAndCompute( InputArray _image, InputArray _mask,
bool useOCL = false;
#endif
Mat image = _image.getMat(), mask = _mask.getMat();
Mat image = _image.getMat(), mask;
if (!_mask.empty())
{
threshold(_mask, mask, 0, 255, THRESH_BINARY);
}
if( image.type() != CV_8UC1 )
cvtColor(_image, image, COLOR_BGR2GRAY);
@@ -1134,7 +1138,7 @@ void ORB_Impl::detectAndCompute( InputArray _image, InputArray _mask,
}
copyMakeBorder(currImg, extImg, border, border, border, border,
BORDER_REFLECT_101+BORDER_ISOLATED);
BORDER_REFLECT_101 + BORDER_ISOLATED);
if (!mask.empty())
copyMakeBorder(currMask, extMask, border, border, border, border,
BORDER_CONSTANT+BORDER_ISOLATED);

View File

@@ -168,4 +168,31 @@ BIGDATA_TEST(Features2D_ORB, regression_opencv_python_537) // memory usage: ~3
ASSERT_NO_THROW(orbPtr->detectAndCompute(img, noArray(), kps, fv));
}
TEST(Features2D_ORB, MaskValue)
{
Mat gray = imread(cvtest::findDataFile("features2d/tsukuba.png"), IMREAD_GRAYSCALE);
ASSERT_FALSE(gray.empty());
cv::Rect roi(gray.cols/4, gray.rows/4, gray.cols/2, gray.rows/2);
Mat mask255 = Mat::zeros(gray.size(), CV_8UC1);
Mat mask1 = Mat::zeros(gray.size(), CV_8UC1);
mask255(roi).setTo(255);
mask1(roi).setTo(1);
Ptr<ORB> orb = cv::ORB::create();
vector<KeyPoint> keypoints_mask255, keypoints_mask1;
Mat descriptors_mask255, descriptors_mask1;
orb->detectAndCompute(gray, mask255, keypoints_mask255, descriptors_mask255, false);
orb->detectAndCompute(gray, mask1, keypoints_mask1, descriptors_mask1, false);
ASSERT_EQ(keypoints_mask255.size(), keypoints_mask1.size())
<< "Number of keypoints differs between mask values 255 and 1";
Mat diff = descriptors_mask255 != descriptors_mask1;
ASSERT_EQ(countNonZero(diff), 0);
}
}} // namespace