Opencv 实战学习总结 三 (绘制基本图形 线、矩形、圆、椭圆、多边形填充、文本)

Opencv 实战学习总结 三

Opencv 实战学习总结 三 (绘制基本图形 线、矩形、圆、椭圆、多边形填充、文本)_第1张图片

/// 
/// 绘制图像
/// 
void testpainttestsharp() 
{
	Mat image = imread("3.jpg");
	Point p1 = Point(20, 30);
	Point p2;
	p2.x = 200;
	p2.y = 300;
	Scalar color = Scalar(0,0,255);
	//线
	line(image,p1,p2,color,10,LINE_8);

	//矩形
	Scalar color1 = Scalar(255, 0, 255);
	Rect rect = Rect(400,100,100,200);
	rectangle(image,rect, color1,2,LINE_AA);
	//椭圆
	ellipse(image,p2,Size(100,200),90,0,360,color1,2,LINE_8);
	//圆
	circle(image,p2,100, color1,10, LINE_8);

	Point pts[1][5];
	pts[0][0] = Point(100,100);
	pts[0][1] = Point(100, 200);
	pts[0][2] = Point(200, 200);
	pts[0][3] = Point(200, 100);
	pts[0][4] = Point(100, 100);

	Scalar color2 = Scalar(255, 0, 0);
	const Point* ppts[] = { pts[0] };
	int npt[] = { 5 };
	//填充
	fillPoly(image, ppts, npt,1, color2, 8);
	//文本
	Scalar color3 = Scalar(10, 255, 200);
	putText(image,"hello opencv",Point(0,400), FONT_HERSHEY_COMPLEX,2.0,color3,1,8);

	namedWindow("image", WINDOW_AUTOSIZE);
	imshow("image", image);
	waitKey(0);
}

你可能感兴趣的:(opencv,opencv)