How can I see SIFT keypoints from an image?

asked 2013-11-26 03:57:54 -0600

Nihad gravatar image

I tried to see SIFT keypoints from an image. I use following code, but I got some error msg given below: OpenCV Error: Assertion failed (scn == 1 && (dcn == 3 || dcn == 4)) in unknown f unction, file ........\ocv\opencv\modules\imgproc\src\color.cpp, line 2453

Here is my code:

#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>

#include <vector>

using namespace std;
using namespace cv;

int main(int argc, char *argv[])
{        
  Mat image = imread("TestImage.jpg");

  // Create smart pointer for SIFT feature detector.
  Ptr<FeatureDetector> featureDetector = FeatureDetector::create("SIFT");
  vector<KeyPoint> keypoints;

  // Detect the keypoints
  featureDetector->detect(image, keypoints); // NOTE: featureDetector is a pointer hence the '->'.

  //Similarly, we create a smart pointer to the SIFT extractor.
  Ptr<DescriptorExtractor> featureExtractor = DescriptorExtractor::create("SIFT");

  // Compute the 128 dimension SIFT descriptor at each keypoint.
  // Each row in "descriptors" correspond to the SIFT descriptor for each keypoint
  Mat descriptors;
  featureExtractor->compute(image, keypoints, descriptors);

  // If you would like to draw the detected keypoint just to check
  Mat outputImage;
  Scalar keypointColor = Scalar(255, 0, 0);     // Blue keypoints.
  drawKeypoints(image, keypoints, outputImage, keypointColor, DrawMatchesFlags::DEFAULT);

  namedWindow("Output");
  imshow("Output", outputImage);



  return 0;

}

How can I see SIFT keypoints?

edit retag flag offensive close merge delete

Comments

Mat image = imread("TestImage.jpg",CV_LOAD_IMAGE_GRAYSCALE); //Load as grayscale

albertofernandez gravatar imagealbertofernandez ( 2013-11-26 04:28:30 -0600 )edit

Thanks. Now it works fine.

Nihad gravatar imageNihad ( 2013-11-26 04:44:11 -0600 )edit