鼠标绘制线段
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;
}