I am using the following code to extract and draw the SIFT keypoints in an image. But in my code, i haven't specified that how many keypoints i want to extract? so, it completely depends upon the image how many keypoints it have.
What i want: I want to specify that i need maximum 20 keypoints in an image. If 20 keypoints are not present then no need to proceed further or if keypoints are more than 20 then just consider the most important 20 keypoints.
My current code:
//To store the keypoints that will be extracted by SIFT
vector<KeyPoint> keypoints;
//The SIFT feature extractor and descriptor
SiftDescriptorExtractor detector;
Mat input;
//open the file
input = imread("image.jpg", 0);
//detect feature points
detector.detect(input, keypoints);
///Draw Keypoints
Mat keypointImage;
keypointImage.create( input.rows, input.cols, CV_8UC3 );
drawKeypoints(input, keypoints, keypointImage, Scalar(255,0,0));
imshow("Keypoints Found", keypointImage);
waitKey(0);