鼠标绘制线段
void draw_circle(int event, int x, int y, int flags, void* param)
{
cv::Mat* img = (cv::Mat*)param;
if (event == cv::EVENT_LBUTTONDBLCLK)
{
cv::circle(*img, cv::Point(x, y), 100, cv::Scalar(0, 0, 255), -1);
}
}
void draw_line(int event, int x, int y, int flags, void* param)
{
static cv::Point draw_line_startp;
cv::Mat* img = (cv::Mat*)param;
if (event == cv::EVENT_LBUTTONDOWN)
{
draw_line_startp = cv::Point(x, y);
}
else if (event == cv::EVENT_MOUSEMOVE && (flags & cv::EVENT_FLAG_LBUTTON))
{
cv::Point end_point(x, y);
cv::line(*img, draw_line_startp, end_point, cv::Scalar(0, 0, 255), 2);
draw_line_startp = end_point;
}
}
void opencvTool::drawingByMouse()
{
cv::Mat img(512, 512, CV_8UC3, cv::Scalar(255, 255, 255));
cv::namedWindow("image");
cv::setMouseCallback("image", draw_line, &img);
while (true)
{
imshow("image", img);
if (cv::waitKey(20) == 27)
{
break;
}
}
cv::destroyAllWindows();
return;
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53