i am using openCV FastFeatureDetector to extract fast keypoints from image.
but the number of the FastFeatureDetector detect is not a const number.
i want set the max keypoints number FastFeatureDetector get.
Can i specify the FAST key points number i get when using openCV FastFeatureDetector
How?
Asked
Active
Viewed 1,659 times
2

Moore liu
- 31
- 1
- 8
-
The number of keypoints depends on the image. You cannot force the detector to find keypoints where there aren't any. So the only way to get a constant number is to specify the maximum number of output points and then guarantee that every image will have more than that. – System123 May 30 '14 at 14:47
3 Answers
1
I recently had this problem and after a brief search I found DynamicAdaptedFeatureDetector that iteratively detects keypoints until the desired number is found.
code:
int maxKeypoints, minKeypoints;
Ptr<FastAdjuster> adjust = new FastAdjuster();
Ptr<FeatureDetector> detector = new DynamicAdaptedFeatureDetector(adjust,minKeypoints,maxKeypoints,100);
vector<KeyPoint> keypoints;
detector->detect(image, keypoints);

zedv
- 1,459
- 12
- 23
1
I am offering main part of the code, in that case you can set the number of key-points as what you expected. Good luck.
# define MAX_FEATURE 500 // specify maximum expected feature size
string detectorType = "FAST";
string descriptorType = "SIFT";
detector = FeatureDetector::create(detectorType);
extractor = DescriptorExtractor::create(descriptorType);
Mat descriptors;
vector<KeyPoint> keypoints;
detector->detect(img, keypoints);
if( keypoints.size() > MAX_FEATURE )
{
cout << " [INFO] key-point 1 size: " << keypoints.size() << endl;
KeyPointsFilter::retainBest(keypoints, MAX_FEATURE);
}
cout << " [INFO] key-point 2 size: " << keypoints.size() << endl;
extractor->compute(img, keypoints, descriptors);

neouyghur
- 1,577
- 16
- 31
0
The other solution is to detect as many keypoints as possible with a low threshold and apply adaptive non-maximal suppression (ANMS) described in this paper. You can specify the number of points you need. Additionally, for free, you get your points homogenously distributed on the image. Codes can be found here.

Alex Bailo
- 197
- 2
- 15