c++ - 使用 SetMouseCallback、c++、OpenCV 获取像素信息的问题
问题描述
我一直在尝试获取有关我单击的像素的信息。我一直在使用函数 SetMouceCallback,老实说我不知道它是如何工作的。
void startGUI()
{
VideoCapture video;
Mat frame1;
video.open("/Users/Dominik/Desktop/Legia22.mov");
video.read(frame1);
Mat img = frame1.clone();
namedWindow("My Window", 1);
setMouseCallback("My Window", onMouse, &img);
imshow("My Window", img);
//********* I want to use leftClicks[] here
waitKey(0);
}
static void onMouse(int event, int x, int y, int, void* param)
{
Mat &img = *((Mat*)param);
static int counter=0;
Point leftClicks[4];
if ( event == EVENT_LBUTTONDOWN && counter<4)
{
Vec3b val = img.at< Vec3b >(y,x);
cout << "left button clicked pos - (" << x << ", " << y << ")" <<"\t colour bgr: "<< val << endl;
leftClicks[counter].x = x;
leftClicks[counter].y = y;
circle(img, Point(x,y), 4, SCALAR_BLUE, -1);
imshow("My Window", img);
counter++;
}
}
以下代码工作正常。显示窗口,在第一帧我可以画 4 个圆圈。这些点打印在终端中。所以基本上我想要做的是将数组 leftClicks[4] 从函数中取出,以便在其他函数中进行进一步处理,例如。****** 在哪里。问题是函数 onMouse 的类型必须是 void 并且参数不能更改。
我注意到函数 setMouseCallback 已经很好地指定了 onMouse 函数必须是什么,并且不能对函数 onMouse 进行任何更改......
那么如何从 onMouse 函数中获取数组 leftClicks[] 呢?
解决方案
推荐阅读
- c# - 将字节发布到 graphql api
- python - 如何在python中将字符串转换为具有值的数组
- asp.net-mvc - 如何根据Controller中的RoleId调用ajax内的Session?
- bash - 如何在 bash 脚本中以 gb 为单位获取 ram 大小?
- functional-programming - F#如何定义“递归”变量
- php - 数组元素无法显示
- angular - Angular 上的 Agora 集成获得“CORS 政策:无‘Access-Control-Allow-Origin’”
- c++ - 通过 initializer-list 初始化一个 n 维数组
- pine-script - 如何使此警报在 Tradingview 中起作用?
- php - 您可以从 PHP 脚本运行交互式 linux 命令吗?