Segfault when accessing keypoint[i].pt (keypoint coordinates) [closed]

asked 2015-05-14 12:24:24 -0500

theo-b gravatar image

updated 2015-05-15 01:07:00 -0500

I'm trying to access the coordinates of keypoints picked up from an image by SimpleBlobDetect. As per here my code is as follows:

vector<KeyPoint> keypoints;
float kpt_x, kpt_y;

for(int i=0; i<=keypoints.size(); i++)
{
     kpt_x = keypoints[i].pt.x;
     kpt_y = keypoints[i].pt.y;
}

But this throws a segfault on each line within the for loop.

Why? Is this the correct way of accessing keypoint coordinates?

EDIT: When I run debugger, it shows that the error is on the line kpt_x = keypoints[i].pt.x;

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by berak
close date 2015-05-15 07:57:07.332935

Comments

2

for(int i=0; i<=keypoints.size(); i++) it must be: i<keypoints.size(); here. you're doing one too many. (it is nothing special about keypoints here, just basic c++)

berak gravatar imageberak ( 2015-05-14 13:11:31 -0500 )edit

OK sorry, that fixed it. Should I delete my question?

theo-b gravatar imagetheo-b ( 2015-05-15 06:56:25 -0500 )edit