0
所以这是我在openCV中设置MouseEvent的尝试,我的观点是根据鼠标事件在给定点绘制一些东西。任何想法有什么不对? 我跟着这个教程:https://docs.opencv.org/3.3.0/db/d5b/tutorial_py_mouse_handling.html使用鼠标作为画笔
#include<opencv2\core\core.hpp>
#include<opencv2\imgproc\imgproc.hpp>
#include<opencv2\highgui\highgui.hpp>
#include<opencv2\ml\ml.hpp>
#include<iostream>
#include<conio.h>
using namespace std;
using namespace cv;
int radius = 5;
Mat img;
int ix = 1;
int iy = 1;
//mouse callback function
void drawCircle(int event, int x, int y, int, void* param) {
if (event == CV_EVENT_LBUTTONDOWN)
{
cout << "x = " << x
<< "\t y = " << y
<< endl;
circle(img, Point(x, y), 10, Scalar(255,255,255), 10);
}
//line(img, Point(10, 10), Point(x, y), Scalar(0, 0, 255), 3);
}
int main() {
img = imread("image.png");
if (img.empty()) {
cout << "\nerror reading image" << endl;
_getch();
return -1;
}
namedWindow("Image",1);
imshow("Image", img);
setMouseCallback("Image", drawCircle);
waitKey(0);
return 0;
}
为什么它不画我的图像上的圆或线?谢谢!
感谢您的回复。可悲的是,我没有足够的特权来满足您的答案。我改变了waitKey(20)!= 27(ESC),你的代码只是让窗口立即关闭。还是非常感谢这个建议。 –
谢谢,我将它改为您的修补程序。不要担心选票:-) –