2

i have to convert SURF descriptor to keypoints to mark it on the image.I have found the conversion function Converting Mat to Keypoint?. But the results i am getting are very strange.This is the following function.

vector<KeyPoint> mat_to_keypoints(Mat mat) {

  vector<KeyPoint>  c_keypoints;
  for ( int i = 0; i < mat.rows; i++) {

      Vec<float, 7> v = mat.at< Vec<float, 7> >(i,0);
      KeyPoint kp(v[0],v[1],v[2],v[3],v[4], (int)v[5], (int)v[6]);
      c_keypoints.push_back(kp);
  }
  return c_keypoints;
}

And this is my sample code

 SurfDescriptorExtractor surfDesc;
 Mat descriptors1;

 surfDesc.compute(img_test, keypoints1, descriptors1);
 Point2f p;
 std::vector<cv::KeyPoint> keypoint1_;

 keypoint1_= mat_to_keypoints(descriptors1);

for(int i=0;i<keypoint1_.size();i++)
{
   p = keypoint1_[i].pt;
  cout<<p<<endl;
}

There are the original keypoints

  [287.016, 424.287] 
  [286.903, 424.413] 

And these are keypoints after converting from descriptor to keypoints

-0.001208060.00063669 
00 
00 
00 
00 
0.002944490.00162154 
-0.0005055370.000337795 
0.00683623-0.00150546 

Could some one suggest me,how to convert from descriptors to keypoints?

Community
  • 1
  • 1
sri
  • 25
  • 3
  • Converting descriptors to keypoints does not really make sense. Can you explain, why you want to do this? Maybe then it is easier to help you. – sietschie Sep 09 '13 at 18:24

1 Answers1

5

Your are messing up descriptors with keypoints. Descriptors represent the feature vector associated to keypoints. Descriptors don't include the position (X,Y) of the patch they describe.

You cannot convert from a set of descriptors to a set of keypoints/points.

You can convert keypoints from points with this static method (undocumented):

vector<Point2f> points1; 
KeyPoint::convert(keypoints1, points1);

Sadly there are many undocumented/hidden function very helpful in OpenCV.

dynamic
  • 46,985
  • 55
  • 154
  • 231
  • Hey thanks for the reply.But my problem is in converting descriptos to keypoints.The points are same with the function you provided. – sri Sep 09 '13 at 17:19
  • 2
    As I said you cannot convert from descriptors to keypoints. Keypoints and descriptors are saved in two different position: `vector` and `Mat`. The ith item in the vector is the keypoint associated with the ith row of the Mat – dynamic Sep 09 '13 at 18:33
  • @dynamic so glad I found this. Do you know if there is a similar way to do the opposite being going from vector to vector? – C.Radford Jul 05 '17 at 20:30