Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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::imread("f:/open/me.jpg");

cv::namedWindow("Original");

cv::setMouseCallback("Original", mouse_call, (void*)&points); (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){ if(event==cv::EVENT_LBUTTONDOWN){

    std::vector<cv::Point>* ptPtr = (std::vector<cv::Point>*)param;

 std::vector<cv::point>* ptPtr = (std::vector<cv::point>*)param;
            ptPtr->push_back(cv::Point(x,y));

ptPtr->push_back(cv::Point(x,y));
}

And, when I'm trying to access the vector-elements with: points[0].x 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

click to hide/show revision 3
No.3 Revision

updated 2016-03-04 07:55:41 -0600

berak gravatar image

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> std::vector<cv::Point> points;   

cv::Mat img = cv::imread("f:/open/me.jpg");

cv::imread("f:/open/me.jpg"); cv::namedWindow("Original"); cv::setMouseCallback("Original", mouse_call, (void*)&points); int X,Y;

cv::namedWindow("Original");

cv::imshow("Original",img);

cv::setMouseCallback("Original", mouse_call, (void*)&points);

int X,Y;

cv::imshow("Original",img);

And in Callback:

Callback:

static void mouse_call(int event,int x,int y, int, void* param) { if(event==cv::EVENT_LBUTTONDOWN){

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:

with: points[0].x

points[0].x

points[0].y

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