背景减法库(BGS Library = background subtraction library)包含了37种背景建模算法,也是目前国际上关于背景建模技术研究最全也最权威的资料。本文将更加详细的介绍背景减法库(BGS Library)的基本框架与入口函数main()的功能。
BGS库的整体框架在背景建模技术(二)中已经全部给出,此处从函数的角度再次给出BGS库的基本框架,有利于代码的修改与维护。
如下图所示是基于C++的BGS库的函数流程图:
接下来将会对每个函数进行更加详细的分析。
首先,先看入口函数main(),代码如下:
#include "Config.h" #include "VideoAnalysis.h" #include <iostream> using namespace std; namespace bgslibrary { class Main { private: Main(); public: static void start(int argc, const char **argv) { cout << "-----------------------------------------" << endl; cout << "Background Subtraction Library v1.9.2 " << endl; cout << "http://code.google.com/p/bgslibrary " << endl; cout << "by: " << endl; cout << "Andrews Sobral (andrewssobral@gmail.com) " << endl; cout << "Optimized by: " << endl; cout << "Rui-Dong Fang(National Huaqiao University)" << endl; cout << "-----------------------------------------" << endl; cout << "Using OpenCV version " << CV_VERSION << endl; try { int key = KEY_ESC; do { VideoAnalysis* videoAnalysis = new VideoAnalysis; if (videoAnalysis->setup(argc, argv)) ///videoAnalysis->setup(argc, argv) { videoAnalysis->start(); cout << "Processing finished, enter:" << endl; cout << "R - Repeat" << endl; cout << "Q - Quit" << endl; key = cv::waitKey(); } cv::destroyAllWindows(); delete videoAnalysis; } while (key == KEY_REPEAT); } catch (const std::exception& ex) { cout << "std::exception:" << ex.what() << endl; return; } catch (...) { cout << "Unknow error" << endl; return; } #ifdef WIN32 //system("pause"); #endif } }; } int main(int argc, const char **argv) { bgslibrary::Main::start(argc, argv); return 0; }
在main()函数中,除了打印出相关信息和设置waitKey()以外,主要就是调用了VIdeoAnalysis.cpp(将在下一篇博文中分析)中的videoAnalysis->setup(argc, argv)和videoAnalysis->start()。下面给出Main.cpp的代码流程图:
时间: 2024-09-16 10:03:36