简体   繁体   English

设置Android OpenCV中的关键点数量

[英]Set number of keypoints in Android OpenCV

I'm trying to run feature detection on an image using some of the inbuilt OpenCV feature detectors. 我正在尝试使用一些内置的OpenCV特征检测器对图像进行特征检测。 However, I only want to detect the top/best n features present in the image (lets say 30 for this example). 但是,我只想检测图像中存在的顶部/最佳n个特征(对于这个例子,假设为30)。 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 . 我已经尝试在SO上找到解决方案,但我能找到的唯一解决方案不适用于OpenCV的Android版本 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. 我能想到的唯一可行的方法就是采用前30个特征,但我认为这不会很好,因为它们可能都聚集在图像的一个部分。 So I was wondering if anyone knows how the top 30 features can be chosen (if indeed they can). 所以我想知道是否有人知道如何选择前30个功能(如果他们确实可以)。 I don't mind which feature detection algorithm the solution is for (MSER, ORB, SIFT, SURF, STAR, GFTT, etc.). 我不介意解决方案适用于哪种特征检测算法(MSER,ORB,SIFT,SURF,STAR,GFTT等)。

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. 我还要求每次都检测到30个特征,因此使用灵敏度直到它“正确”不是一个选项。

EDIT: the reason for needing to find exactly 30 features is that I am going to use them to train my detector. 编辑:需要找到30个功能的原因是我将使用它们来训练我的探测器。 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. 我的想法是,我将从一组训练图像中获取30个特征,然后使用结果在场景中再次找到该对象。 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. 由于训练图像将是对象的近距离,因此特征不会聚集在图像的一个部分中并不重要。

Whilst I haven't been able to find a way of setting the number of keypoints to search for, I have been able to work out how to extract the correct number of keypoints afterwards. 虽然我找不到设置要搜索的关键点数量的方法,但我已经能够找出如何在之后提取正确数量的关键点。 Doing this isn't computationally efficient but from the comments I received I don't think doing it before is possible. 这样做不是计算效率,但从我收到的评论中我不认为以前这样做是可能的。

My keypoints variable is: 我的关键点变量是:

private final MatOfKeyPoint mTargetKeypoints = new MatOfKeyPoint();

After it has been "filled" with features (it seems to stop after 500) the individual features can be extracted by transforming it to an array (where each element of the array is a feature. 在它被“填充”特征(它似乎在500之后停止)之后,可以通过将其转换为数组来提取各个特征(其中数组的每个元素都是特征。

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

When I print the above the result is: 当我打印上面的结果是:

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

The individual information can then be extracted with the inbuilt Keypoint functions, eg: 然后可以使用内置的Keypoint函数提取个人信息,例如:

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

This SO question indicates that the response indicates "how good" the keypoint is. 这个问题表明响应表明关键点“有多好”。 Thus from here it is relatively simple to pick the best 30 features to use. 因此,从这里选择最好使用的30个功能相对简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM