示例代码
#include <opencv2/opencv.hpp>
using namespace cv;
void onMouseHandle(int event, int x, int y, int flags, void *param)
{
switch (event) {
// 鼠标移动
case EVENT_MOUSEMOVE:
break;
// 左键按下
case EVENT_LBUTTONDOWN:
circle(*(Mat*)param, Point(x, y), 20, Scalar(0, 0, 255));
break;
default:
break;
}
imshow("原图", *(Mat*)param);
}
int main(int argc, char const *argv[])
{
Mat image = imread("1.jpg");
namedWindow("原图");
setMouseCallback("原图", onMouseHandle, &image);
waitKey(0);
return 0;
}
运行结果
image.png
网友评论