Set the number of cue points in Android OpenCV

I am trying to run feature detection on an image using some of OpenCV's built-in feature detectors. However, I only want to detect the top / best n features present in the image (say 30 for this example). I already have some code that will find the functions and then use them to identify that object in other images, but I cannot work out how to limit the number of keypoints found. I am initializing various detectors / extractors / matches as shown 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 tried to find a solution already on SO, but the only solutions I can find are not for the Android OpenCV version . Attempting similar methods for these solutions also didn't work.

The only way I can think this might work is to just take the first 30 functions, but I don't think that will work well as they can all be grouped into one part of the image. So I was wondering if anyone could find out how to pick the top 30 features (if they really can). I don't mind which function detection algorithm is for (MSER, ORB, SIFT, SURF, STAR, GFTT, etc.).

I also require exactly 30 features to be detected each time, so playing with sensitivity until "about right" is an option.

EDIT: The reason you need to find exactly 30 functions is because I'm going to use them to train my detector. The idea is that I get 30 functions from each set of training images and then use the result to then find the object in the scene again. Since the training images will be close to the object, it doesn't matter that the features won't be grouped into one part of the image.

+3


source to share


1 answer


Until I could find a way to set the number of cue points to search for, I was able to figure out how to extract the correct number of cue points from them. Doing this is not computationally efficient, but from the comments I received, I don't think it is possible to do this.

My keypoints variable:

private final MatOfKeyPoint mTargetKeypoints = new MatOfKeyPoint();

      

After it has been "filled" with functions (it seems to stop after 500), individual functions can be retrieved by converting it to an array (where each element of the array is a feature.

mTargetKeypoints.toArray()[0]; //NOTE: Not actual code, used in a print statement

      



When I print the above result:

KeyPoint [pt = {82.0, 232.0}, size = 31.0, angle = 267.77094, response = 0.0041551706, octave = 0, class_id = -1]

Individual information can then be retrieved using built-in Keypoint functions, for example:

mTargetKeypoints.toArray()[0].pt.x //Printing outputs x location of feature.
mTargetKeypoints.toArray()[0].response // Printing outputs response of feature. 

      

This question indicates that the answer indicates "how good" the key point is. So it's relatively easy to pick the top 30 features from here to use.

0


source







All Articles