为
问题描述:
我现在有两个鼠标回调函数在一个单一的OpenCV窗口不同的鼠标操作使用单个或多个mousecallback都在做不同的东西为
// Function to choose midpoint of a circle
static void onMouse(int event, int x, int y, int, void*)
{
//Detect Mouse button event
if(event == EVENT_LBUTTONDOWN)
{
//store point clicked
}
}
第二回调吸引了来自一个点的直线单击窗口而上鼠标左键按住至其新版本发布
// Draws a line from the beginning of a point to another.
// This line is the diameter of a circle
// The first point isn't the coordinates stored by onMouse
static void DrawLine(int event, int x, int y, int, void*)
{
switch (event)
{
case EVENT_LBUTTONDOWN:
// start point
case EVENT_LBUTTONUP:
//endpoint
break;
case EVENT_MOUSEMOVE:
if(clicked)
{
// store point
}
break;
default : break;
}
}
如何调用分别各功能按顺序点。即首先运行onMouse回调和运行DrawLine的回调函数
Main()
{
setMouseCallback("WinName", onMouse, 0);
setMouseCallback("WinName", DrawLine, 0);
// capture first frame of video
cap >> frame;
// set midpoint when onMouse is called
// set coordinates of the line when DrawLine is called
while (true)
{
cap >> frame;
// do the rest of your stuff here
}
}
答
只需使用一个回调函数onMouse
:
setMouseCallback("WinName", onMouse, 0);
然后,您可以拨打DrawLine
从onMouse
:
static void DrawLine(int event, int x, int y)
{
// Do something...
}
static void onMouse(int event, int x, int y, int, void*)
{
//Detect Mouse button event
if(SOME_CONDITION)
{
// Do something...
}
else
{
DrawLine(event, x, y)
}
}
通常你按照CTRL, ALT, SHIFT等修饰符做不同的事情。
这是我基于按键的原创想法。我希望有一个内置的opencv函数来处理这个 – MaskedAfrican
做什么,到底是什么? – Miki
我决定改用这个方法。少混乱。 – MaskedAfrican