I'm trying to run feature detection on an image using some of the inbuilt OpenCV feature detectors. However, I only want to detect the top/best n features present in the image (lets say 30 for this example). I already have code that will find features and then use them to identify that object in other images, but I can't work out how to restrict the number of keypoints found. I initialise the various detectors/extractors/matchers as below:
private final FeatureDetector mFeatureDetector = FeatureDetector.create(FeatureDetector.ORB);
private final DescriptorExtractor mDescriptorExtractor = descriptorExtractor.create(DescriptorExtractor.ORB);
private final DescriptorMatcher mDescriptorMatcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMINGLUT);
I have tried to find a solution already on SO but the only solutions I can find aren't for the android version of OpenCV. Trying similar methods to these solutions also didn't work.
The only method I can think of that might work is just taking the first 30 features, but I don't think this will work well as they might all be clustered in one part of the image. So I was wondering if anyone knows how the top 30 features can be chosen (if indeed they can). I don't mind which feature detection algorithm the solution is for (MSER, ORB, SIFT, SURF, STAR, GFTT, etc.).
I also require that exactly 30 features be detected each time, so playing with the sensitivity until it's "about right" isn't an option.
EDIT: the reason for needing to find exactly 30 features is that I am going to use them to train my detector. The idea is that I will get 30 features from each of a set of training images and then use the result to then find the object again in a scene. As the training images will be close ups of the object it doesn't matter that the features won't be clustered in one part of the image.