Ask Your Question
1

OpenCV Why does number of SIFT keypoints go over threshold?

asked 2015-11-29 01:26:19 -0600

angubenko gravatar image

Hi,

I created SIFT constructor, with Threshold = 100

cv::Ptr<feature2d> f2d = xfeatures2d::SIFT::create(100);

f2d->compute(image, keypoint, descriptor);

Then I extract descriptors from sequence of images and for some images I receive number of keypoints bigger than limit by one. Please see descriptors print below:

[128 x 101]

[128 x 100]

[128 x 100]

[128 x 101]

[128 x 100]

[128 x 100]

[128 x 101]

[128 x 100]

Why does it happen? Do have incorrect understanding of nfeatures attribute?

edit retag flag offensive close merge delete

Comments

I think that your are right @LBerger. I tested with this image and this code:

  cv::Ptr<cv::Feature2D> sift = cv::xfeatures2d::SIFT::create(100);    
  sift->detectAndCompute(matImg, cv::Mat(), kpts, descriptors);
  if(kpts.size() > 100) {
    std::cout << "kpts=" << kpts.size() << std::endl;
    std::map<float, std::vector<cv::KeyPoint> > map;
    for(size_t i = 0; i < kpts.size(); i++) {
      map[kpts[i].response].push_back(kpts[i]);
      std::cout << "response=" << std::fixed << std::setprecision(9) << kpts[i].response << std::endl;
    }

    std::cout << "map=" << map.size() << std::endl;
  }

I got 61 keypoints with different response and 101 in total.

Eduardo gravatar imageEduardo ( 2015-11-29 10:52:46 -0600 )edit

That sounds like a bug to me. In this case algorithm should just ignore other features. Accorfing documentation it supposes to keep numer of best features.

angubenko gravatar imageangubenko ( 2015-11-29 15:20:43 -0600 )edit

I don't think it's a bug but if you think so you can make an issue or improve doc using a pull request. You are welcome

LBerger gravatar imageLBerger ( 2015-11-30 01:35:21 -0600 )edit

It is not a bug, but as suggested due to the fact that keypoints can have the same score or strength. It can therefore only limit it to the closest correct amount. What you should do is physically limit the output afterwards. It will never be 99, always 100 or more.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-11-30 03:11:17 -0600 )edit
1

That's what I did, thanks.

angubenko gravatar imageangubenko ( 2015-11-30 03:43:48 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2015-11-29 08:40:50 -0600

LBerger gravatar image

updated 2015-11-29 09:29:16 -0600

It is written in doc : The number of best features to retain. The features are ranked by their scores (measured in SIFT algorithm as the local contrast)

May be I'm wrong but if you've 99 features and two after with same score algorithm can give you 100 or 101 features.

edit flag offensive delete link more

Comments

Thank you. This part "The number of best features to retain" of description seems a little bit confusing. Why do we need these extra keypoints if they have same rank? What usage of these extra keypoints? Do you think I should open an issue?

angubenko gravatar imageangubenko ( 2015-11-30 03:47:53 -0600 )edit

I guess the logic is:

  • we have 99 keypoints
  • the next best keypoint set contains for example 4 keypoints
  • so which one of the 4 keypoints we should add ? The first one that comes in the image ?
  • so I think that they choose to not choose and add all the keypoints in the set

A warning in the documentation should be added I think.

Edit:

You can find the implementation details here:

Eduardo gravatar imageEduardo ( 2015-11-30 04:13:30 -0600 )edit

Adding a notice might indeed be a good idea!

StevenPuttemans gravatar imageStevenPuttemans ( 2015-11-30 06:43:03 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-11-29 01:26:19 -0600

Seen: 1,743 times

Last updated: Nov 29 '15