Ask Your Question
0

Opencv fails to capture click down early after previous

asked 2013-02-22 17:29:02 -0600

Darker gravatar image

I have written a very simple UI class for open CV (based on drawing buttons on OpenCV matrices), but it seems, that OpenCV has some sort of event handler bug:
When I click down, up and down second down click event is not captured, if I click too fast. However, if I click down, up, down and up though the second down remains ignored the second up event is captured, no matter how fast I try to click.
Debug output (1 = down, -1 = up):

Button: 1    //slow clicks
Button: -1
Button: 1
Button: -1
Button: 1
Button: -1
Button: 1
Button: -1
Button: 1   //started clicking fast
Button: -1
Button: -1
Button: 1
Button: -1
Button: -1
Button: 1
Button: -1
Button: -1
Button: 1

Because I already happened to be downvoted for posting questions without code, here is some code:

void Opencv_UI::event_process(int evt, int x, int y, int flags) 
{
    int button = 0;
    switch(evt) 
    {
        case CV_EVENT_LBUTTONDOWN : button=1; break;
        case CV_EVENT_LBUTTONUP : button=-1; break;
        case CV_EVENT_RBUTTONDOWN : button=3; break;
        case CV_EVENT_RBUTTONUP : button=-3; break;
    }
    if(button==1||button==-1)
      std::cout<<"Button: "<<button<<"\n";
        //Code below does not affect event performance, I tryed the script with all this commented out
    int button_count = buttons.size();
    for(int i=0; i<button_count; i++) //Informs buttons about mouse event
    {
        buttons[i]->mouse(x, y, button);
    }
    this->render();    //Renders buttons affected by click/mousemove
}
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2013-02-23 05:23:56 -0600

berak gravatar image

updated 2013-02-23 05:26:28 -0600

if you start clicking fast, CV_EVENT_LBUTTONDBLCLK gets triggered.

so it's not losing clicks, but interprets them in a different way.

you'll have to extend your switch statement there.

edit flag offensive delete link more

Comments

Thank you, I'd never have figured this out! :D

Darker gravatar imageDarker ( 2013-02-23 06:41:59 -0600 )edit

i'd have neither, without just printing values to cout ..

berak gravatar imageberak ( 2013-02-23 07:09:25 -0600 )edit

Question Tools

Stats

Asked: 2013-02-22 17:29:02 -0600

Seen: 588 times

Last updated: Feb 23 '13