mirror of
https://github.com/opencv/opencv.git
synced 2025-06-08 01:53:19 +08:00
Merge pull request #17772 from mshabunin:fix-match-umat-mask
This commit is contained in:
commit
d2469edd10
@ -622,15 +622,20 @@ void DescriptorMatcher::checkMasks( InputArrayOfArrays _masks, int queryDescript
|
|||||||
if( isMaskSupported() && !masks.empty() )
|
if( isMaskSupported() && !masks.empty() )
|
||||||
{
|
{
|
||||||
// Check masks
|
// Check masks
|
||||||
size_t imageCount = std::max(trainDescCollection.size(), utrainDescCollection.size() );
|
const size_t imageCount = std::max(trainDescCollection.size(), utrainDescCollection.size() );
|
||||||
CV_Assert( masks.size() == imageCount );
|
CV_Assert( masks.size() == imageCount );
|
||||||
for( size_t i = 0; i < imageCount; i++ )
|
for( size_t i = 0; i < imageCount; i++ )
|
||||||
{
|
{
|
||||||
if( !masks[i].empty() && (!trainDescCollection[i].empty() || !utrainDescCollection[i].empty() ) )
|
if (masks[i].empty())
|
||||||
|
continue;
|
||||||
|
const bool hasTrainDesc = !trainDescCollection.empty() && !trainDescCollection[i].empty();
|
||||||
|
const bool hasUTrainDesc = !utrainDescCollection.empty() && !utrainDescCollection[i].empty();
|
||||||
|
if (hasTrainDesc || hasUTrainDesc)
|
||||||
{
|
{
|
||||||
int rows = trainDescCollection[i].empty() ? utrainDescCollection[i].rows : trainDescCollection[i].rows;
|
const int rows = hasTrainDesc ? trainDescCollection[i].rows : utrainDescCollection[i].rows;
|
||||||
CV_Assert( masks[i].rows == queryDescriptorsCount &&
|
CV_Assert(masks[i].type() == CV_8UC1
|
||||||
masks[i].cols == rows && masks[i].type() == CV_8UC1);
|
&& masks[i].rows == queryDescriptorsCount
|
||||||
|
&& masks[i].cols == rows);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -565,7 +565,6 @@ TEST(Features2d_DMatch, issue_11855)
|
|||||||
1, 1, 1);
|
1, 1, 1);
|
||||||
Mat targets = (Mat_<uchar>(2, 3) << 1, 1, 1,
|
Mat targets = (Mat_<uchar>(2, 3) << 1, 1, 1,
|
||||||
0, 0, 0);
|
0, 0, 0);
|
||||||
|
|
||||||
Ptr<BFMatcher> bf = BFMatcher::create(NORM_HAMMING, true);
|
Ptr<BFMatcher> bf = BFMatcher::create(NORM_HAMMING, true);
|
||||||
vector<vector<DMatch> > match;
|
vector<vector<DMatch> > match;
|
||||||
bf->knnMatch(sources, targets, match, 1, noArray(), true);
|
bf->knnMatch(sources, targets, match, 1, noArray(), true);
|
||||||
@ -577,4 +576,18 @@ TEST(Features2d_DMatch, issue_11855)
|
|||||||
EXPECT_EQ(0.0f, match[0][0].distance);
|
EXPECT_EQ(0.0f, match[0][0].distance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(Features2d_DMatch, issue_17771)
|
||||||
|
{
|
||||||
|
Mat sources = (Mat_<uchar>(2, 3) << 1, 1, 0,
|
||||||
|
1, 1, 1);
|
||||||
|
Mat targets = (Mat_<uchar>(2, 3) << 1, 1, 1,
|
||||||
|
0, 0, 0);
|
||||||
|
UMat usources = sources.getUMat(ACCESS_READ);
|
||||||
|
UMat utargets = targets.getUMat(ACCESS_READ);
|
||||||
|
vector<vector<DMatch> > match;
|
||||||
|
Ptr<BFMatcher> ubf = BFMatcher::create(NORM_HAMMING);
|
||||||
|
Mat mask = (Mat_<uchar>(2, 2) << 1, 0, 0, 1);
|
||||||
|
EXPECT_NO_THROW(ubf->knnMatch(usources, utargets, match, 1, mask, true));
|
||||||
|
}
|
||||||
|
|
||||||
}} // namespace
|
}} // namespace
|
||||||
|
Loading…
Reference in New Issue
Block a user