opencv c++图像几何形状绘制(14)

  • Post author:
  • Post category:其他


用途:框住图像中某个物体。(人脸识别)

调用API:

rectangle(输入图像,矩形,颜色(Scalar形式),线宽,线形,shift参数)

circle(输入图像,圆心坐标(Point),半径,颜色,线宽,线形,shift参数);

line(输入图像, 左边界坐标, 右边界坐标, 颜色,线宽,线形,shift参数);

ellipse(输入图像, 椭圆, 颜色,线宽,线形);

矩形定义示例:

Rect rect;

rect.x = 200;

rect.y = 200;

rect.width = 160;

rect.height = 160;

椭圆定义示例:

RotatedRect rrt;

rrt.center = Point(280, 280);

rrt.size = Size(100, 150);

rrt.angle = 90.0;

1、用矩形和圆圈框住某个目标:

void QuickDemo::drawing_Demo(Mat& image)
{
	//定义矩形及其参数
	Rect rect;
	rect.x = 200;
	rect.y = 200;
	rect.width = 160;
	rect.height = 160;
	//在输入图像上绘制矩形
	rectangle(image, rect, Scalar(0, 0,255), 3, 8,0);
	circle(image, Point(280, 280), 80, Scalar(255, 0, 0), 3, 8, 0);
	imshow("绘制演示", image);
}

结果:

2、对比度框图应用

void QuickDemo::drawing_Demo(Mat& image)
{
	//定义矩形及其参数
	Rect rect;
	rect.x = 200;
	rect.y = 200;
	rect.width = 160;
	rect.height = 160;
	在输入图像上绘制矩形
	//rectangle(image, rect, Scalar(0, 0,255), 3, 8,0);
	//circle(image, Point(280, 280), 80, Scalar(255, 0, 0), 3, 8, 0);

	// 创建同输入图像大小类型的Mat bg,在其上绘制矩形和圆圈
	Mat bg = Mat::zeros(image.size(), image.type());
	rectangle(bg, rect, Scalar(0, 0,255), -1, 8,0);
	circle(bg, Point(280, 280), 80, Scalar(255, 0, 0), 3, 8, 0);
    line(bg, Point(200, 200), Point(360, 360), Scalar(0,255, 0), 3, 8, 0);
	//将输入图像和bg做对比度处理,结果赋予dst
	Mat dst;
	addWeighted(image, 0.9, bg, 0.3, 0, dst);
	imshow("绘制演示", dst);
}

结果:



版权声明:本文为lucust原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。