码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-05-14 14:22:32      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:背景建模   bgs library   视频分析   videoanalysis   


视频分析模块主要包含两个函数,一个是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;
	}

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


技术分享





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

标签:背景建模   bgs library   视频分析   videoanalysis   

原文地址:http://blog.csdn.net/frd2009041510/article/details/45719133

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!