#include <stdio.h>
#include <iostream>
#include <string>
#include <opencv2\opencv.hpp>
using namespace std;
using namespace cv;
void callback_width_brush(int,void*);
void callback_mouse(int event, int x, int y, int flags, void*);
int value = 2;
Mat img;
Point pre_point;
int main()
{
img = Mat::zeros(Size(500, 500), CV_8UC1);
imshow("交互窗口", img);
createTrackbar("画笔粗细", "交互窗口", &value, 20, callback_width_brush, 0);
setMouseCallback("交互窗口", callback_mouse, 0);
waitKey(0);
return 0;
}
static void callback_width_brush(int, void*)
{
imshow("交互窗口", img);
}
void callback_mouse(int event, int x, int y, int flags, void*)
{
if (event == EVENT_LBUTTONDOWN)
{
pre_point = Point(x, y);
}
if ((event == EVENT_MOUSEMOVE) && (flags == EVENT_FLAG_LBUTTON))
{
line(img, pre_point, Point(x, y), Scalar(255), value > 2 ? value : 2, 5, 0);
pre_point = Point(x, y);
imshow("交互窗口", img);
}
}
|