Segfault when accessing keypoint[i].pt (keypoint coordinates) [closed]
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;
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++)OK sorry, that fixed it. Should I delete my question?