如何在opencv和c++中使用鼠标在图像上绘制线条
How can i draw lines on a image using mouse in opencv and c++?
我的目标是在opencv和c++中使用鼠标在图像中画一条线。我在网上看了不同的代码,但在有了一些想法后,我想自己尝试一下。我可能完全错了,但我只是个初学者。所以,我想尝试一下,但仍然不起作用,所以我想把它发布在这里。如果可能的话,请纠正我的错误。
POINT p;
GetCursorPos(&p);
bool drawing;
int x;
int y;
int startx,starty;
int finishx,finishy;
int z;
int l;
Mat a;
a = imread("a.JPG");
if(GetKeyState(VK_LBUTTON) & 0x80 != 0)
{
drawing = true;
x = p.x;
y = p.y;
startx = x;//the starting position to start the drawing
starty = y;
}
if(GetKeyState(VK_RBUTTON) &0x80 != 0)
{
drawing = false;
z= p.x;
l = p.y;
finishx = z;
finishy = l;
}
if(drawing==true)
{
line(a,Point(startx,starty),Point(finishx,finishy),Scalar(0,0,255),1);
imshow("test image",a);
}
您需要将划线代码放入setMouseCallback()
指定的回调函数中。OpenCV有一个如何进行回调的演示。另请参阅此问题的答案使用python在open cv中使用鼠标事件绘制矩形或直线(答案在C++中)
相关文章:
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 如何使用OpenCV将RBG图像转换为HSV,并将H、S和V值保存为C++中的3个独立图像
- OpenCV EqualizeHist()从彩色图像创建黑白图像
- 将"打开的CV图像"中的"颜色"转换为整数格式
- 平均图像时图像损坏
- 在C++中使用GDAL可以将图像的像素坐标转换为lat,long吗
- 在 macOS 中使用 C/C++ 设置鼠标光标图像
- 忽略父 Qt 快速图像的透明区域的鼠标区域单击事件
- 如何使用SFML鼠标移动分别移动多个图像
- 如何翻转图像并同时用枪指着鼠标?(SFML)
- 在调整大小窗口时,如何使用鼠标单击来获取图像的坐标
- 如何在打开的cv c ++中单击鼠标右键时从视频中捕获图像
- 在c++或c中获取当前鼠标光标图像
- 用鼠标打开不同的 Url,单击两个不同的图像C++
- 使用 OpenCV 将鼠标指针悬停在图像上时在图像上打印像素坐标
- 如何将光标(鼠标指针对象)转换为bmp图像的自动序列
- 如何在opencv中使用鼠标点击在图像上绘制线条
- 如何在opencv和c++中使用鼠标在图像上绘制线条
- 使用鼠标单击在图像上绘制多条线失败
- 显示自定义图像并能够捕捉鼠标输入