3

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);
skm
  • 5,015
  • 8
  • 43
  • 104
  • well, the next step would be feature extraction, right ?. you could cluster the features using BOW to a certain number(like 20) and do similarity measures ( like SVM ) based on the clustered BOW feature – berak Mar 16 '14 at 11:59
  • @berak: yes, i know that. I am already doing it. But i want to limit the number of extracted keypoints at this step. So, i am confused about how can i limit the number of keypoints – skm Mar 16 '14 at 12:21

1 Answers1

6

It can be done by using the following line:

//The SIFT feature extractor and descriptor
SiftDescriptorExtractor detector(20); 
skm
  • 5,015
  • 8
  • 43
  • 104