Ask Your Question
0

Values returned by MouseCallBack?

asked 2014-11-07 11:51:13 -0600

HandsomeJoe gravatar image

How do I get values defined within my MouseCallBack function to be accessible to separate Functions, Objects & Modules that are part of larger application? e.g. I tried putting my MouseCallback function within an upper level function and tried to use Return to get the values I wanted. I also tried putting it within a Class. Both scenarios had Global variables defined for the values I needed but I am not able to get the values I need to pass later on to other functions or objects in the larger application.

edit retag flag offensive close merge delete

Comments

I should have shared that I am using openCV in Python.

HandsomeJoe gravatar imageHandsomeJoe ( 2014-11-07 18:45:37 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-11-07 14:29:42 -0600

juanmanpr gravatar image

Hello, I am not sure I understand well your problem, but I will give you an example on how I deal with this:

void Manager::init(){
  ...//code
  cv::setMouseCallback( "SELECT BOX", onMouse, &tinfo1 );    
  ...//code
}

void Manager::onMouse( int event, int x, int y, int , void* p ){
    trackerinfo* info = (trackerinfo*) p;
    switch ( event ){
    case cv::EVENT_LBUTTONDOWN:
    //set origin of the bounding box
    info->startSelection = true;
    info->bbox.x = x;
    info->bbox.y = y;
    break;
        ... /*other events...*/
    }
}

So, as you can see, you can use information that is modified inside the "onMouse" event method by passing a pointer to your data (In the example a "trackerinfo" object). As the callback expects a (void*) you have to apply proper casting for your own data types. You can also see that there is no inconvenient on using a class method as callback. Is this what you are looking for?

edit flag offensive delete link more

Comments

Hello and thank you for your reply. Unfortunately I am using openCV in Python as I don't know C.

HandsomeJoe gravatar imageHandsomeJoe ( 2014-11-07 18:44:36 -0600 )edit

Question Tools

Stats

Asked: 2014-11-07 11:51:13 -0600

Seen: 246 times

Last updated: Nov 07 '14