opencv设置鼠标回调 [英] opencv set mouse callback
本文介绍了opencv设置鼠标回调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是OpenCV的初学者,想在控制台中打印通过单击定义的像素(RGB格式)的特定值.
I'm a beginner in OpenCV and would like to print in my console the specific value of a pixel (RGB format) that I define by clicking on it.
经过一些搜索,我设法找到了我在图片上点击的坐标.
After some searches I managed to prind the coordinates of the click I make on the image.
如果有人知道该怎么做,请修改我正在使用的这段代码:
If anyone knows how to do that please modify this code that I am using:
void mouseEvent (int evt, int x, int y, int flags, void* param)
{
if (evt == CV_EVENT_LBUTTONDOWN)
{
printf("%d %d\n",x ,y );
}
}
这就是我用来调用函数的地方:
and this is what I use to call the function:
cvSetMouseCallback("blah blah", mouseEvent, 0);
推荐答案
将图像放置在称为框架的Mat中,然后:
Place your image in a Mat called frame, then:
namedWindow("test");
cvSetMouseCallback("test", mouseEvent, &frame);
char key = 0;
while ((int)key != 27) {
imshow("test", frame);
key = waitKey(1);
}
其中mouseEvent定义为:
where mouseEvent is defined as:
void mouseEvent(int evt, int x, int y, int flags, void* param) {
Mat* rgb = (Mat*) param;
if (evt == CV_EVENT_LBUTTONDOWN) {
printf("%d %d: %d, %d, %d\n",
x, y,
(int)(*rgb).at<Vec3b>(y, x)[0],
(int)(*rgb).at<Vec3b>(y, x)[1],
(int)(*rgb).at<Vec3b>(y, x)[2]);
}
}
这篇关于opencv设置鼠标回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文