我为开放式 CV 编写了一个非常简单的 UI 类(基于 OpenCV 矩阵上的绘图按钮),但似乎 OpenCV 存在某种事件处理程序错误:
当我单击向下时,未捕获向上和向下第二次向下单击事件,如果我点击太快。但是,如果我单击向下、向上、向下和向上,尽管第二次向下仍然被忽略,则无论我尝试单击多快,都会捕获第二次向上事件。
调试输出(1 = 向下,-1 = 向上):
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
因为我已经碰巧因为发布没有代码的问题而被否决,所以这里有一些代码:
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
}