OpenCV基本图形绘制之绘制直线

先上代码

#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/video.hpp>

using namespace cv;
using namespace std;

#define WINDOW_WIDTH 600//自定义窗口大小的宏 

void DrawLine(Mat img, Point start, Point end) {
	int thickness = 1;
	int lineType = 8;
	line(img,
		start,
		end,
		Scalar(255, 0, 0),
		thickness,
		lineType);
}

int main(int argc, char** argv)
{
	Mat img = Mat::zeros(WINDOW_WIDTH, WINDOW_WIDTH, CV_8UC3);

	DrawLine(img, Point(200, 200), Point(400, 400));
	DrawLine(img, Point(400, 400), Point(200, 300));
	imshow("name1", img);
	waitKey(0);
	return 0;
}

效果

函数解析

 绘制直线还是稍微简单点,给定一个画板,然后给定起点和重点,剩下的一些画笔的配置,就可以了。

猜你喜欢

转载自blog.csdn.net/sono_io/article/details/124254752