Skip to content

Commit eaf69a7

Browse files
author
Long Vuong
committed
update with upstream
1 parent 6eb6af3 commit eaf69a7

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

corelib/src/Features2d.cpp

+20-2
Original file line numberDiff line numberDiff line change
@@ -741,13 +741,13 @@ std::vector<cv::KeyPoint> Feature2D::generateKeypoints(const cv::Mat & image, co
741741
if(roi.x || roi.y)
742742
{
743743
// Adjust keypoint position to raw image
744-
for(std::vector<cv::KeyPoint>::iterator iter=sub_keypoints.begin(); iter!=sub_keypoints.end(); ++iter)
744+
for(std::vector<cv::KeyPoint>::iterator iter=subKeypoints.begin(); iter!=subKeypoints.end(); ++iter)
745745
{
746746
iter->pt.x += roi.x;
747747
iter->pt.y += roi.y;
748748
}
749749
}
750-
keypoints.insert( keypoints.end(), sub_keypoints.begin(), sub_keypoints.end() );
750+
keypoints.insert( keypoints.end(), subKeypoints.begin(), subKeypoints.end() );
751751
}
752752
}
753753
UDEBUG("Keypoints extraction time = %f s, keypoints extracted = %d (grid=%dx%d, mask empty=%d)",
@@ -2122,6 +2122,24 @@ std::vector<cv::KeyPoint> ORBOctree::generateKeypointsImpl(const cv::Mat & image
21222122

21232123
(*_orb)(imgRoi, maskRoi, keypoints, descriptors_);
21242124

2125+
// OrbOctree ignores the mask, so we have to apply it manually here
2126+
if(!keypoints.empty() && !maskRoi.empty())
2127+
{
2128+
std::vector<cv::KeyPoint> validKeypoints;
2129+
validKeypoints.reserve(keypoints.size());
2130+
cv::Mat validDescriptors;
2131+
for(size_t i=0; i<keypoints.size(); ++i)
2132+
{
2133+
if(maskRoi.at<unsigned char>(keypoints[i].pt.y+roi.y, keypoints[i].pt.x+roi.x) != 0)
2134+
{
2135+
validKeypoints.push_back(keypoints[i]);
2136+
validDescriptors.push_back(descriptors_.row(i));
2137+
}
2138+
}
2139+
keypoints = validKeypoints;
2140+
descriptors_ = validDescriptors;
2141+
}
2142+
21252143
if((int)keypoints.size() > this->getMaxFeatures())
21262144
{
21272145
limitKeypoints(keypoints, descriptors_, this->getMaxFeatures());

0 commit comments

Comments
 (0)