背景建模技术(三):背景减法库(BGS Library)的基本框架与入口函数main()的功能

背景减法库(BGS Library = background subtraction library)包含了37种背景建模算法,也是目前国际上关于背景建模技术研究最全也最权威的资料。本文将更加详细的介绍背景减法库(BGS Library)的基本框架与入口函数main()的功能。

 

BGS库的整体框架在背景建模技术(二)中已经全部给出,此处从函数的角度再次给出BGS库的基本框架,有利于代码的修改与维护。

 

如下图所示是基于C++的BGS库的函数流程图:

 

 

接下来将会对每个函数进行更加详细的分析。

 

首先,先看入口函数main(),代码如下:

 

 

  1. #include "Config.h"  
  2. #include "VideoAnalysis.h"  
  3. #include <iostream>  
  4.   
  5. using namespace std;  
  6.   
  7. namespace bgslibrary  
  8. {  
  9.     class Main  
  10.     {  
  11.         private:  
  12.         Main();  
  13.   
  14.         public:  
  15.         static void start(int argc, const char **argv)  
  16.         {  
  17.             cout << "-----------------------------------------" << endl;  
  18.             cout << "Background Subtraction Library v1.9.2     " << endl;  
  19.             cout << "http://code.google.com/p/bgslibrary       " << endl;  
  20.             cout << "by:                                       " << endl;  
  21.             cout << "Andrews Sobral (andrewssobral@gmail.com)  " << endl;  
  22.             cout << "Optimized by:                             " << endl;  
  23.             cout << "Rui-Dong Fang(National Huaqiao University)" << endl;  
  24.             cout << "-----------------------------------------" << endl;  
  25.             cout << "Using OpenCV version " << CV_VERSION << endl;  
  26.   
  27.             try  
  28.             {  
  29.                 int key = KEY_ESC;  
  30.   
  31.                 do  
  32.                 {  
  33.                     VideoAnalysis* videoAnalysis = new VideoAnalysis;  
  34.   
  35.                     if (videoAnalysis->setup(argc, argv))    ///videoAnalysis->setup(argc, argv)  
  36.                     {  
  37.                         videoAnalysis->start();  
  38.   
  39.                         cout << "Processing finished, enter:" << endl;  
  40.                         cout << "R - Repeat" << endl;  
  41.                         cout << "Q - Quit" << endl;  
  42.   
  43.                         key = cv::waitKey();  
  44.                     }  
  45.   
  46.                     cv::destroyAllWindows();  
  47.                     delete videoAnalysis;  
  48.   
  49.                 }   
  50.                 while (key == KEY_REPEAT);  
  51.             }  
  52.             catch (const std::exception& ex)  
  53.             {  
  54.                 cout << "std::exception:" << ex.what() << endl;  
  55.                 return;  
  56.             }  
  57.             catch (...)  
  58.             {  
  59.                 cout << "Unknow error" << endl;  
  60.                 return;  
  61.             }  
  62.   
  63. #ifdef WIN32  
  64.     //system("pause");  
  65. #endif  
  66.         }  
  67.     };  
  68. }  
  69.   
  70. int main(int argc, const char **argv)  
  71. {  
  72.     bgslibrary::Main::start(argc, argv);  
  73.     return 0;  
  74. }  

 

 


在main()函数中,除了打印出相关信息和设置waitKey()以外,主要就是调用了VIdeoAnalysis.cpp(将在下一篇博文中分析)中的videoAnalysis->setup(argc, argv)和videoAnalysis->start()。下面给出Main.cpp的代码流程图:

 

 

posted @ 2015-05-18 13:56  于为  阅读(663)  评论(0编辑  收藏  举报