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

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

 

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

 

该函数的代码如下:

 

 

  1. bool VideoAnalysis::setup(int argc, const char **argv)  
  2. {  
  3.     bool flag = false;  
  4.   
  5.     const char* keys =  
  6.                         "{hp|help|false|Print help message}"  
  7.                         "{uf|use_file|false|Use video file}"  
  8.                         "{fn|filename||Specify video file}"  
  9.                         "{uc|use_cam|false|Use camera}"  
  10.                         "{ca|camera|0|Specify camera index}"  
  11.                         "{co|use_comp|false|Use mask comparator}"  
  12.                         "{st|stopAt|0|Frame number to stop}"  
  13.                         "{im|imgref||Specify image file}" ;  
  14.       
  15.     cv::CommandLineParser cmd(argc, argv, keys);  
  16.   
  17.     use_command  
  18.     if (argc <= 1 || cmd.get<bool>("help") == true)  
  19.     {  
  20.         cout << "Usage: " << argv[0] << " [options]" << endl;  
  21.         cout << "Avaible options:" << endl;  
  22.         cmd.printParams();  
  23.         return false;  
  24.     }  
  25.   
  26.     use_file  
  27.     use_file = cmd.get<bool>("use_file");  
  28.     if (use_file)  
  29.     {  
  30.         filename = cmd.get<string>("filename");  
  31.   
  32.         if (filename.empty())  
  33.         {  
  34.             cout << "Specify filename" << endl;  
  35.             return false;  
  36.         }  
  37.   
  38.         flag = true;  
  39.     }  
  40.   
  41.     use_camera  
  42.     use_camera = cmd.get<bool>("use_cam");  
  43.     if (use_camera)  
  44.     {  
  45.         cameraIndex = cmd.get<int>("camera");  
  46.         flag = true;  
  47.     }  
  48.   
  49.     use_comp  
  50.     if (flag == true)  
  51.     {  
  52.         use_comp = cmd.get<bool>("use_comp");  
  53.         if (use_comp)  
  54.         {  
  55.             frameToStop = cmd.get<int>("stopAt");  
  56.             imgref = cmd.get<string>("imgref");  
  57.   
  58.             if (imgref.empty())  
  59.             {  
  60.                 cout << "Specify image reference" << endl;  
  61.                 return false;  
  62.             }  
  63.         }  
  64.     }  
  65.   
  66.     return flag;  
  67. }  


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

 

 

 

 

2、VideoAnalysis::start()

 

该函数的代码如下:

 

 

  1. void VideoAnalysis::start()  
  2. {  
  3.     //cout << "Press 'ESC' to stop..." << endl;  
  4.   
  5.     do  
  6.     {  
  7.         videoCapture = new VideoCapture;  
  8.         frameProcessor = new FrameProcessor;  
  9.   
  10.         frameProcessor->init();  
  11.         frameProcessor->frameToStop = frameToStop;  
  12.         frameProcessor->imgref = imgref;  
  13.   
  14.         videoCapture->setFrameProcessor(frameProcessor);///setFrameProcessor  
  15.   
  16.         if (use_file)  
  17.             videoCapture->setVideo(filename);///setVideo  
  18.   
  19.         if (use_camera)  
  20.             videoCapture->setCamera(cameraIndex);///setCamera  
  21.   
  22.         videoCapture->start();///start  
  23.   
  24.         if (use_file || use_camera)  
  25.             break;  
  26.   
  27.         frameProcessor->finish();  
  28.   
  29.         int key = cvWaitKey(500);  
  30.         if (key == KEY_ESC)  
  31.             break;  
  32.   
  33.         delete frameProcessor;  
  34.         delete videoCapture;  
  35.   
  36.     }   
  37.     while (1);  
  38.   
  39.     delete frameProcessor;  
  40.     delete videoCapture;  
  41. }  

 

 

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

 

 

转载于:https://www.cnblogs.com/ywsoftware/p/4511773.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值