Skip to content

Commit

Permalink
update with upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Long Vuong committed Feb 26, 2024
1 parent 6eb6af3 commit eaf69a7
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions corelib/src/Features2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -741,13 +741,13 @@ std::vector<cv::KeyPoint> Feature2D::generateKeypoints(const cv::Mat & image, co
if(roi.x || roi.y)
{
// Adjust keypoint position to raw image
for(std::vector<cv::KeyPoint>::iterator iter=sub_keypoints.begin(); iter!=sub_keypoints.end(); ++iter)
for(std::vector<cv::KeyPoint>::iterator iter=subKeypoints.begin(); iter!=subKeypoints.end(); ++iter)
{
iter->pt.x += roi.x;
iter->pt.y += roi.y;
}
}
keypoints.insert( keypoints.end(), sub_keypoints.begin(), sub_keypoints.end() );
keypoints.insert( keypoints.end(), subKeypoints.begin(), subKeypoints.end() );
}
}
UDEBUG("Keypoints extraction time = %f s, keypoints extracted = %d (grid=%dx%d, mask empty=%d)",
Expand Down Expand Up @@ -2122,6 +2122,24 @@ std::vector<cv::KeyPoint> ORBOctree::generateKeypointsImpl(const cv::Mat & image

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

// OrbOctree ignores the mask, so we have to apply it manually here
if(!keypoints.empty() && !maskRoi.empty())
{
std::vector<cv::KeyPoint> validKeypoints;
validKeypoints.reserve(keypoints.size());
cv::Mat validDescriptors;
for(size_t i=0; i<keypoints.size(); ++i)
{
if(maskRoi.at<unsigned char>(keypoints[i].pt.y+roi.y, keypoints[i].pt.x+roi.x) != 0)
{
validKeypoints.push_back(keypoints[i]);
validDescriptors.push_back(descriptors_.row(i));
}
}
keypoints = validKeypoints;
descriptors_ = validDescriptors;
}

if((int)keypoints.size() > this->getMaxFeatures())
{
limitKeypoints(keypoints, descriptors_, this->getMaxFeatures());
Expand Down

0 comments on commit eaf69a7

Please sign in to comment.