OpenCV入坑备忘4——简单绘图2

上一篇OpenCV入坑备忘3——简单绘图

1、画多边形

在这里插入图片描述

#include<iostream>
#include<opencv2/opencv.hpp>
#define w 400

using namespace cv;

/// Function headers
void MyEllipse(Mat img, double angle);
void MyFilledCircle(Mat img, Point center);
void MyPolygon(Mat img);


VideoCapture VCap;//视频容器

int main(void) {

	int NumP = 0;

	/// Create black empty images
	Mat image;
	//= Mat::zeros(w, w, CV_8UC3);//生成一个400x400的矩阵,每个像素点占8bit,无符号整型,4通道图像
	VCap.open(0);
	if (!VCap.isOpened())//判断是否初始化/读取成功。与.open相关联(先后顺序)
		return -1;//如是,关闭程序

	Point rook_points[1][20];//创建坐标二维数组
	rook_points[0][0] = Point(w / 4, 7 * w / 8);
	rook_points[0][1] = Point(3 * w / 4, 7 * w / 8);
	rook_points[0][2] = Point(3 * w / 4, 13 * w / 16);
	rook_points[0][3] = Point(11 * w / 16, 13 * w / 16);
	rook_points[0][4] = Point(19 * w / 32, 3 * w / 8);
	rook_points[0][5] = Point(3 * w / 4, 3 * w / 8);
	rook_points[0][6] = Point(3 * w / 4, w / 8);
	rook_points[0][7] = Point(26 * w / 40, w / 8);
	rook_points[0][8] = Point(26 * w / 40, w / 4);
	rook_points[0][9] = Point(22 * w / 40, w / 4);
	rook_points[0][10] = Point(22 * w / 40, w / 8);
	rook_points[0][11] = Point(18 * w / 40, w / 8);
	rook_points[0][12] = Point(18 * w / 40, w / 4);
	rook_points[0][13] = Point(14 * w / 40, w / 4);
	rook_points[0][14] = Point(14 * w / 40, w / 8);
	rook_points[0][15] = Point(w / 4, w / 8);
	rook_points[0][16] = Point(w / 4, 3 * w / 8);
	rook_points[0][17] = Point(13 * w / 32, 3 * w / 8);
	rook_points[0][18] = Point(5 * w / 16, 13 * w / 16);
	rook_points[0][19] = Point(w / 4, 13 * w / 16);

	const Point* ppt[1] = { rook_points[0] };
	int npt[] = { 20 };//坐标点数总数量
	while (1)
	{
		VCap.read(image);
		polylines(
			image,
			ppt,
			npt,
			1,
			1,
			Scalar(0, 0, 0),
			8
		);
		if (NumP >= 500)NumP = 0;
		imshow("画多边形", image);
		waitKey(33);
	}
	waitKey(90000);
	return(0);
}

在这里插入图片描述

2、填充多边形

在这里插入图片描述

#include<iostream>
#include<opencv2/opencv.hpp>
#define w 400

using namespace cv;

/// Function headers
void MyEllipse(Mat img, double angle);
void MyFilledCircle(Mat img, Point center);
void MyPolygon(Mat img);


VideoCapture VCap;//视频容器

int main(void) {

	int NumP = 0;

	/// Create black empty images
	Mat image;
	//= Mat::zeros(w, w, CV_8UC3);//生成一个400x400的矩阵,每个像素点占8bit,无符号整型,4通道图像
	VCap.open(0);
	if (!VCap.isOpened())//判断是否初始化/读取成功。与.open相关联(先后顺序)
		return -1;//如是,关闭程序

	Point rook_points[1][20];
	rook_points[0][0] = Point(w / 4, 7 * w / 8);
	rook_points[0][1] = Point(3 * w / 4, 7 * w / 8);
	rook_points[0][2] = Point(3 * w / 4, 13 * w / 16);
	rook_points[0][3] = Point(11 * w / 16, 13 * w / 16);
	rook_points[0][4] = Point(19 * w / 32, 3 * w / 8);
	rook_points[0][5] = Point(3 * w / 4, 3 * w / 8);
	rook_points[0][6] = Point(3 * w / 4, w / 8);
	rook_points[0][7] = Point(26 * w / 40, w / 8);
	rook_points[0][8] = Point(26 * w / 40, w / 4);
	rook_points[0][9] = Point(22 * w / 40, w / 4);
	rook_points[0][10] = Point(22 * w / 40, w / 8);
	rook_points[0][11] = Point(18 * w / 40, w / 8);
	rook_points[0][12] = Point(18 * w / 40, w / 4);
	rook_points[0][13] = Point(14 * w / 40, w / 4);
	rook_points[0][14] = Point(14 * w / 40, w / 8);
	rook_points[0][15] = Point(w / 4, w / 8);
	rook_points[0][16] = Point(w / 4, 3 * w / 8);
	rook_points[0][17] = Point(13 * w / 32, 3 * w / 8);
	rook_points[0][18] = Point(5 * w / 16, 13 * w / 16);
	rook_points[0][19] = Point(w / 4, 13 * w / 16);

	const Point* ppt[1] = { rook_points[0] };
	int npt[] = { 20 };

	while (1)
	{
		VCap.read(image);
		fillPoly(image,
			ppt,
			npt,
			1,
			Scalar(255, 100, 50),
			8);

		if (NumP >= 500)NumP = 0;
		imshow("填充多边形", image);
		waitKey(33);
	}


	waitKey(90000);
	return(0);
}

在这里插入图片描述

3、绘制文字

在这里插入图片描述
在这里插入图片描述

#include<iostream>
#include<opencv2/opencv.hpp>
#define w 400

using namespace cv;

/// Function headers
void MyEllipse(Mat img, double angle);
void MyFilledCircle(Mat img, Point center);
void MyPolygon(Mat img);


VideoCapture VCap;//视频容器

int main(void) {

	int NumP = 0;

	/// Create black empty images
	Mat image;
	//= Mat::zeros(w, w, CV_8UC3);//生成一个400x400的矩阵,每个像素点占8bit,无符号整型,4通道图像
	VCap.open(0);
	if (!VCap.isOpened())//判断是否初始化/读取成功。与.open相关联(先后顺序)
		return -1;//如是,关闭程序

	Point rook_points[1][20];
	rook_points[0][0] = Point(w / 4, 7 * w / 8);
	rook_points[0][1] = Point(3 * w / 4, 7 * w / 8);
	rook_points[0][2] = Point(3 * w / 4, 13 * w / 16);
	rook_points[0][3] = Point(11 * w / 16, 13 * w / 16);
	rook_points[0][4] = Point(19 * w / 32, 3 * w / 8);
	rook_points[0][5] = Point(3 * w / 4, 3 * w / 8);
	rook_points[0][6] = Point(3 * w / 4, w / 8);
	rook_points[0][7] = Point(26 * w / 40, w / 8);
	rook_points[0][8] = Point(26 * w / 40, w / 4);
	rook_points[0][9] = Point(22 * w / 40, w / 4);
	rook_points[0][10] = Point(22 * w / 40, w / 8);
	rook_points[0][11] = Point(18 * w / 40, w / 8);
	rook_points[0][12] = Point(18 * w / 40, w / 4);
	rook_points[0][13] = Point(14 * w / 40, w / 4);
	rook_points[0][14] = Point(14 * w / 40, w / 8);
	rook_points[0][15] = Point(w / 4, w / 8);
	rook_points[0][16] = Point(w / 4, 3 * w / 8);
	rook_points[0][17] = Point(13 * w / 32, 3 * w / 8);
	rook_points[0][18] = Point(5 * w / 16, 13 * w / 16);
	rook_points[0][19] = Point(w / 4, 13 * w / 16);

	const Point* ppt[1] = { rook_points[0] };
	int npt[] = { 20 };

	while (1)
	{
		VCap.read(image);
		fillPoly(image,
			ppt,
			npt,
			1,
			Scalar(255, 100, 50),
			8);

		putText(image,//绘制文字
			"King",
			Point(80, 30),
			FONT_HERSHEY_SCRIPT_COMPLEX,//字型(见上表)
			1,
			Scalar(0, 0, 0),
			1,
			8
			);

		if (NumP >= 500)NumP = 0;
		imshow("绘制文字", image);
		waitKey(33);
	}


	waitKey(90000);
	return(0);
}

在这里插入图片描述

3.1、显示数据

	char FPS[10] = {'F','P','S',':'};
	char ac=0;
	while (1)
	{
		VCap.set(CV_CAP_PROP_BRIGHTNESS,1);//亮度 1
		VCap.set(CV_CAP_PROP_SATURATION, 50);//饱和度 50
		ac++;
		if (ac >=99)
		{
			ac = 0;
		}
		FPS[4] = ac / 10 + 48;
		FPS[5] = ac % 10 + 48;


		VCap.read(image);
		putText(image,
			FPS,//需要显示的数据
			Point(80, 30),
			FONT_HERSHEY_SIMPLEX,
			1,
			Scalar(0, 0, 0),
			1,
			8
			);

		if (NumP >= 500)NumP = 0;
		imshow("显示数据", image);
		waitKey(30);

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值