select multiple points with mouse (opencv 2.4.9,vs2010,winforms)
Hi,
I'm trying to select multiple points by mouse (with cv::EVENT_LBUTTONDOWN).
So I'm passing the std::vector<cv::point> to the Callback-Function:
//setting the roi manually
std::vector<cv::Point> points;
cv::Mat img = cv::imread("f:/open/me.jpg");
cv::namedWindow("Original");
cv::setMouseCallback("Original", mouse_call, (void*)&points);
int X,Y;
cv::imshow("Original",img);
And in Callback:
static void mouse_call(int event,int x,int y, int, void* param)
{
if(event==cv::EVENT_LBUTTONDOWN){
std::vector<cv::Point>* ptPtr = (std::vector<cv::Point>*)param;
ptPtr->push_back(cv::Point(x,y));
}
And, when I'm trying to access the vector-elements with:
points[0].x
points[0].y
It's compiling, but at runtime i get an error: "Debug Assertion Failed " "Expression: vector subscript out of range"
Any clue ? Thanks