1 | initial version |
One way is to reduce the number of detected keypoints is to increase the threshold. To do this, take a look at this post. You can replace the writeLine()-call with
writeToFile(outputFile, "%YAML:1.0\nthreshold: 30 \nnonmaxSupression: true\n");
to set the parameter for the FAST feature detector.
The other way is to get the best Keypoints is by sorting them according to their response and then pick only the n best ones:
// Detect the features with you Feature Detector
FeatureDetector fastDetector = FeatureDetector.create(FeatureDetector.FAST);
MatOfKeyPoint matrixOfKeypoints;
fastDetector.detect(imageMat, matrixOfKeypoints);
// Sort and select 500 best keypoints
List<KeyPoint> listOfKeypoints = matrixOfKeypoints.toList();
Collections.sort(listOfKeypoints, new Comparator<KeyPoint>() {
@Override
public int compare(KeyPoint kp1, KeyPoint kp2) {
// Sort them in descending order, so the best response KPs will come first
return (int) (kp2.response - kp1.response);
}
});
List<KeyPoint> listOfBestKeypoints = listOfKeypoints.subList(0, 500);
One final remark: Gauglitz et al. 2011 showed that it is important for visual tracking, that keypoints are spatially well distributed, so keep in mind, that you might also want to select the best keypoints according to a grid, so make sure your points are spatially well distributed.
2 | fixed typo |
One way is to reduce the number of keypoints detected keypoints is to increase the threshold. To do this, take a look at this post. You can replace the writeLine()-call with
writeToFile(outputFile, "%YAML:1.0\nthreshold: 30 \nnonmaxSupression: true\n");
to set the parameter for the FAST feature detector.
The other way is to get the best Keypoints is by sorting them according to their response and then pick only the n best ones:
// Detect the features with you Feature Detector
FeatureDetector fastDetector = FeatureDetector.create(FeatureDetector.FAST);
MatOfKeyPoint matrixOfKeypoints;
fastDetector.detect(imageMat, matrixOfKeypoints);
// Sort and select 500 best keypoints
List<KeyPoint> listOfKeypoints = matrixOfKeypoints.toList();
Collections.sort(listOfKeypoints, new Comparator<KeyPoint>() {
@Override
public int compare(KeyPoint kp1, KeyPoint kp2) {
// Sort them in descending order, so the best response KPs will come first
return (int) (kp2.response - kp1.response);
}
});
List<KeyPoint> listOfBestKeypoints = listOfKeypoints.subList(0, 500);
One final remark: Gauglitz et al. 2011 showed that it is important for visual tracking, that keypoints are spatially well distributed, so keep in mind, that you might also want to select the best keypoints according to a grid, so make sure your points are spatially well distributed.