背景建模技术(四):视频分析(VideoAnalysis)模块

简介: <p><br></p> <p>视频分析模块主要包含两个函数,一个是VideoAnalysis::setup(....),其主要功能就是确定测试的视频是视频文件或摄像头输入亦或是采用命令行参数;第二个函数是VideoAnalysis::start(),其主要功能初始化视频处理、设置视频获取方式以及开始视频捕获功能等。</p> <p><br></p> <h2>1、VideoAnalysi


视频分析模块主要包含两个函数,一个是VideoAnalysis::setup(....),其主要功能就是确定测试的视频是视频文件或摄像头输入亦或是采用命令行参数;第二个函数是VideoAnalysis::start(),其主要功能初始化视频处理、设置视频获取方式以及开始视频捕获功能等。


1、VideoAnalysis::setup(....)


该函数的代码如下:


	bool VideoAnalysis::setup(int argc, const char **argv)
	{
		bool flag = false;

		const char* keys =
							"{hp|help|false|Print help message}"
							"{uf|use_file|false|Use video file}"
							"{fn|filename||Specify video file}"
							"{uc|use_cam|false|Use camera}"
							"{ca|camera|0|Specify camera index}"
							"{co|use_comp|false|Use mask comparator}"
							"{st|stopAt|0|Frame number to stop}"
							"{im|imgref||Specify image file}" ;
		
		cv::CommandLineParser cmd(argc, argv, keys);

		////////////use_command
		if (argc <= 1 || cmd.get<bool>("help") == true)
		{
			cout << "Usage: " << argv[0] << " [options]" << endl;
			cout << "Avaible options:" << endl;
			cmd.printParams();
			return false;
		}

		////////////use_file
		use_file = cmd.get<bool>("use_file");
		if (use_file)
		{
			filename = cmd.get<string>("filename");

			if (filename.empty())
			{
				cout << "Specify filename" << endl;
				return false;
			}

			flag = true;
		}

		////////////use_camera
		use_camera = cmd.get<bool>("use_cam");
		if (use_camera)
		{
			cameraIndex = cmd.get<int>("camera");
			flag = true;
		}

		////////////use_comp
		if (flag == true)
		{
			use_comp = cmd.get<bool>("use_comp");
			if (use_comp)
			{
				frameToStop = cmd.get<int>("stopAt");
				imgref = cmd.get<string>("imgref");

				if (imgref.empty())
				{
					cout << "Specify image reference" << endl;
					return false;
				}
			}
		}

		return flag;
	}

它的主要流程如下图所示:





2、VideoAnalysis::start()


该函数的代码如下:


	void VideoAnalysis::start()
	{
		//cout << "Press 'ESC' to stop..." << endl;

		do
		{
			videoCapture = new VideoCapture;
			frameProcessor = new FrameProcessor;

			frameProcessor->init();
			frameProcessor->frameToStop = frameToStop;
			frameProcessor->imgref = imgref;

			videoCapture->setFrameProcessor(frameProcessor);///setFrameProcessor

			if (use_file)
				videoCapture->setVideo(filename);///setVideo

			if (use_camera)
				videoCapture->setCamera(cameraIndex);///setCamera

			videoCapture->start();///start

			if (use_file || use_camera)
				break;

			frameProcessor->finish();

			int key = cvWaitKey(500);
			if (key == KEY_ESC)
				break;

			delete frameProcessor;
			delete videoCapture;

		} 
		while (1);

		delete frameProcessor;
		delete videoCapture;
	}

它的主要流程如下图所示:







目录
相关文章
|
机器学习/深度学习 自然语言处理 算法
Interview:算法岗位面试—11.17下午上海某网**软件公司(上市)技术面之比赛考察、目标检测算法、视频分析算法考点
Interview:算法岗位面试—11.17下午上海某网**软件公司(上市)技术面之比赛考察、目标检测算法、视频分析算法考点
|
存储 数据采集 监控
大数据技术对于视频监控有什么帮助
大数据 ,IT行业术语,是指无法在一定时间范围内用常规软件工具进行捕捉、管理和处理的数据集合,是需要新处理模式才能具有更强的决策力、洞察发现力和流程优化能力的海量、高增长率和多样化的信息资产。
|
机器学习/深度学习 人工智能 算法

热门文章

最新文章