C++随机马赛克图程序

2021-07-04 08:06

阅读:595

标签:other   open   char   struct   pen   int   etl   ber   cal   

效果:

技术分享图片

或者灰度,cell大小可调

 

代码:

#include 
#include 

struct parameters
{
	parameters()
	{
		size=cv::Size(640,480);
		fps=25;
		nF=50;
		save="";
		crossSize= cv::Size(15, 5);
		crossColor = 0;
		show=true;
		seed=cv::getTickCount();
		color=false;
		cellSize = cv::Size(5, 5);
	}

	cv::Size		size;
	int				fps;
	int				nF;
	std::string		save;
	cv::Size		crossSize;
	uchar			crossColor;
	bool			show;
	int64			seed;
	bool			color;
	cv::Size		cellSize;

	void setParas(
		cv::Size		_size,
		int				_fps,
		int				_nF,
		std::string		_save,
		cv::Size		_crossSize,
		uchar			_crossColor,
		bool			_show,
		int64			_seed,
		bool			_color,
		cv::Size		_cellSize)
	{
		size		= _size			   ;
		fps			= _fps			   ;
		nF			= _nF			   ;
		save		= _save			   ;
		crossSize	= _crossSize	   ;
		crossColor = _crossColor       ;
		show		= _show			   ;
		seed		= _seed			   ;
		color		= _color		   ;
		cellSize	= _cellSize			;

	}

	void showParas()
	{
		std::cout  table;
		for (int i = 1; i img.cols || cell.height > img.rows)
	{
		for (size_t j = 0; j (j);
			for (size_t i = 0; i = img.rows)
				lastY = img.rows - 1;

			for (size_t i = 0; i = img.cols)
					lastX = img.cols - 1;

				img.rowRange(j, lastY).colRange(i, lastX).setTo(rng.uniform(0,255));
			}
		}
	}
}

void addCross(cv::Mat & img, cv::Size cSzie, cv::Scalar scalar)
{
	int x_center = (img.cols - 1) / 2, y_center = (img.rows - 1) / 2;
	cv::Point 
		P1_tl(x_center - (cSzie.width - 1) / 2, y_center - (cSzie.height - 1) / 2),
		P1_bd(x_center + (cSzie.width - 1) / 2, y_center + (cSzie.height - 1) / 2),
		P2_tl(x_center - (cSzie.height - 1) / 2, y_center - (cSzie.width - 1) / 2),
		P2_bd(x_center + (cSzie.height - 1) / 2, y_center + (cSzie.width - 1) / 2);

	cv::rectangle(img, P1_tl, P1_bd, scalar, -1);
	cv::rectangle(img, P2_tl, P2_bd, scalar, -1);
}

int main(int argn, char** argv)
{
	parameters _pa;
	getParas(argn, argv, _pa);

	cv::VideoWriter writer(_pa.save, CV_FOURCC(‘M‘, ‘J‘,‘P‘,‘G‘), 
		double(_pa.fps), _pa.size);

	cv::Mat frame0 = cv::Mat::zeros(_pa.size, CV_8UC1);
	cv::Mat frame1 = cv::Mat::zeros(_pa.size, CV_8UC1);
	cv::Mat frame2 = cv::Mat::zeros(_pa.size, CV_8UC1);

	for (int i=0; i<_pa.nf randmatrix _pa.seed i _pa.cellsize addcross _pa.crosssize _pa.crosscolor cv::mat f3 if cv::merge>{frame0,frame1,frame2}, f3);
		else
			cv::merge(std::vector<:mat>{frame0, frame0, frame0}, f3);


		writer 

  

 

 

 

 

使用说明:

见help()

 

C++随机马赛克图程序

标签:other   open   char   struct   pen   int   etl   ber   cal   

原文地址:https://www.cnblogs.com/alexYuin/p/9614107.html


评论


亲,登录后才可以留言!