2

I try to compare two points in two different images, so I want to convert the coordinates to Keypoints to compute with them the description and matching results later.

I found the method:

 keypoint = cv2.KeyPoint(x, y, 0)
 vec = [keypoint]

and it works but as result I get everytime:

 >>>akaze.compute(image, vec)
 ([], None)

Even when I take detected keypoints, convert them to coordinates and back to keypoints (using the structure above) I get the same result.

So, how can I convert the given coordinates to keypoints (for example KAZE keypoints)? Thank you a lot!

Regards, Leo

Leo
  • 125
  • 1
  • 9
  • IN C++ you can use [KeyPoint::convert](http://docs.opencv.org/master/d2/d29/classcv_1_1KeyPoint.html#ab6a67a0ab17d65a1b28502eba424bfde). There should be also the Python binding to this. – Miki Dec 05 '15 at 18:10

1 Answers1

2

The main issue that you created keypoint with zero size. According to documentation, KeyPoint constructor signature requires 3 parameters: x and y coordinates and size (which is keypoint diameter). You set this size to zero.

Thus the first change is setting keypoint diameter, i. e. I supposed that this should work:

keypoint = cv2.KeyPoint(x, y, 5)

but it does not. The reason is that OpenCV keypoint descriptor computer doesn't accept keypoints with default class_id (-1). Really I don't know what is actual class_id purpose (see discussion), but I changed it to zero just because akaze.detect(...) method returns number of keypoint in this field (i. e. 0 for 1st keypoint, 1 for second one and so on). I also set size value to 5 because of the same reason - these values in detected points were from about 4.8 to 5.7.

After these modifications everything became OK, i. e. this code:

keypoints = [cv2.KeyPoint(x, y, 5, _class_id=0)]
akaze = cv2.AKAZE_create("AKAZE")
akaze.compute(image, keypoints)

gave proper result in my case (OpenCV 3.0.0). I suppose that for 2.4.x version it will be also OK.

Community
  • 1
  • 1
avtomaton
  • 4,725
  • 1
  • 38
  • 42