Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Opencv fails to capture click down early after previous

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
}