0

Boy, do I need some help!

I need to iterate over the detected keypoints accessing the x, y, and size fields of each keypoint. The code I am using is almost all copied from tutorials.

Here is a section of the code where I'm having trouble.

// Draw detected blobs as red circles.
Mat im_with_keypoints;

drawKeypoints( im, keypoints, im_with_keypoints, Scalar(0,0,255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS );

// Show blobs
imshow("keypoints", im_with_keypoints );

vector<KeyPoint>::const_iterator it = keypoints.begin(), end = keypoints.end();

cout << "num keypts: " << keypoints.size() << "\n";

for( ; it != end; ++it ) {
  cout << "  kpt x " << it->pt.x << ", y " << it->pt.y << ", size " << it->size << "\n";
}

waitKey(0);

and the output I get.

num keypts: 12
  kpt x -1.#IND, y -1.#IND, size 2.20732
  kpt x 1232.18, y 573.16, size 2.01719
  kpt x 1469.27, y 569.461, size 2.77548
  kpt x 1706.66, y 566.156, size 3.7563
  kpt x 1946.15, y 561.098, size 3.2482
  kpt x 2189.41, y 557.673, size 3.83277
  kpt x 31.4306, y 372.063, size 3.01084
  kpt x 982.995, y 359.899, size 3.33982
  kpt x 1218.8, y 355.892, size 3.8553
  kpt x 1699.99, y 348.004, size 3.38391
  kpt x 1935.74, y 122.263, size 2.75298
  kpt x 2181.73, y 117.866, size 4.08995

I get 12 keypoints. The imshow looks correct and shows 12 keypoints. But, looking at the cout for the first keypoint, the x and y values are soft NANs. The first size is correct. The next 11 x, y, and size values are all correct.

Why are the first keypoint x and y values NANs? I am probably accessing them incorrectly, but everything i have tried gives the same results.

Thanks for any help. Barry.

  • If you try to access the first keypoint before the loop begins, `cout << it->pt.x` or `cout << keypoints[0].pt.x` do you still get incorrect readings? – user3510227 Apr 01 '15 at 07:30
  • I discovered the problem. I am using SimpleBlobDetector. I was setting the param "params.filterByArea = false". This caused the error. I set "params.filterByArea = true; params.minArea = 0.1" and the NANs disappeared. – user1247254 Apr 01 '15 at 07:34

0 Answers0