OpenCV 2.3 with VS 2008 - Mouse Events

Viewed 4812

Obligatory - I'm a newbie. Have a job that involves programming and I'm teaching myself as I go. Needless to say as a teacher I get things wrong frequently and thoroughly.

Where I'm at right now: I've created the class "Graph", it (surprisingly enough) makes graphs. But now I want to make it so that on a mouse click I modify the graph. But I can't seem to get a mouse handler to be a member function of the class.

cv::setMouseCallback(windowName, onMouse, 0); // Set mouse handler to be onMouse

Doesn't work with

cv::setMouseCallback(windowName, Graph::onMouse, 0);

It gives me lack of parameter errors. According to this I can't make it a member function. After following the answer given, it compiles but my this pointer is nulled. Ugh.

OnMouse looks like this:

void onMouse(int event, int x, int y,int, void*)
{
    if (event == CV_EVENT_LBUTTONDOWN)
    {
        cvMoveWindow("Window", 500, 500); //Just to see if stuff happened
    }
    return;
}

I don't care about moving the window, I want to modify the graph itself - which is stored as a cv::Mat variable in a Graph object. And I can't figure out how to do it.

Any help would be appreciated, and I really hope this wasn't just gibberish.

2 Answers
Related