/bgslibrary

A Background Subtraction Library

Primary LanguageC++GNU General Public License v3.0GPL-3.0

BGSLibrary

A Background Subtraction Library

Last Page Update: 14/06/2015

Latest Library Version: 1.9.2 (see Release Notes for more info)

The BGSLibrary was developed by Andrews Sobral and provides an easy-to-use C++ framework based on OpenCV to perform background subtraction (BGS) in videos. The BGSLibrary compiles under Linux, Mac OS X and Windows. Currently the library offers 37¹ BGS algorithms. A large amount of algorithms were provided by several authors. The source code is available under GNU GPL v3 license, the library is free and open source for academic purposes².

For Windows users, a demo project for Visual Studio 2010/2013 is provided. An executable version of BGSLibrary is available for Windows 32 bits and 64 bits. For Linux and Mac users, a Makefile can be used to compile all files.

Note: the BGSLibrary is based on OpenCV 2.X, if you want to use with OpenCV 3.x please check-out our opencv3 branch.

¹ The PBAS algorithm was removed from BGSLibrary because it is based on patented algorithm ViBE.

² Some algorithms of the bgslibrary are free for commercial purposes and others not. First you need to contact the authors of your desired background subtraction method and check with them the appropriate license. For more additional information, please see: Can I use a GPLv3 software as a part of my commercial application?.

Citation

If you use this library for your publications, please cite it as:

@inproceedings{bgslibrary,
author    = {Sobral, Andrews},
title     = {{BGSLibrary}: An OpenCV C++ Background Subtraction Library},
booktitle = {IX Workshop de Visão Computacional (WVC'2013)},
address   = {Rio de Janeiro, Brazil},
year      = {2013},
month     = {Jun},
url       = {https://github.com/andrewssobral/bgslibrary}
}

One chapter about the BGSLibrary has been published in the Handbook on "Background Modeling and Foreground Detection for Video Surveillance".

@incollection{bgslibrarychapter,
author    = {Sobral, Andrews and Bouwmans, Thierry},
title     = {BGS Library: A Library Framework for Algorithm’s Evaluation in Foreground/Background Segmentation},
booktitle = {Background Modeling and Foreground Detection for Video Surveillance},
publisher = {CRC Press, Taylor and Francis Group.}
year      = {2014},
}

Download PDF:

  • Sobral, Andrews. BGSLibrary: An OpenCV C++ Background Subtraction Library. IX Workshop de Visão Computacional (WVC'2013), Rio de Janeiro, Brazil, Jun. 2013. (PDF in brazilian portuguese with english abstract).
  • Sobral, Andrews; Bouwmans, Thierry. "BGS Library: A Library Framework for Algorithm’s Evaluation in Foreground/Background Segmentation". Chapter on the handbook "Background Modeling and Foreground Detection for Video Surveillance", CRC Press, Taylor and Francis Group, 2014. (PDF in english).

References

Some algorithms of the BGSLibrary was used successfully in my following papers:

  • (2014) Sobral, Andrews; Vacavant, Antoine. A comprehensive review of background subtraction algorithms evaluated with synthetic and real videos. Computer Vision and Image Understanding (CVIU), 2014. (Online) (PDF)
  • (2013) Sobral, Andrews; Oliveira, Luciano; Schnitman, Leizer; Souza, Felippe. (Best Paper Award) Highway Traffic Congestion Classification Using Holistic Properties. In International Conference on Signal Processing, Pattern Recognition and Applications (SPPRA'2013), Innsbruck, Austria, Feb 2013. (Online) (PDF)

List of the algorithms available in BGSLibrary

Legend:

Are you in doubt about which algorithm to choose?

Frequently, the question arises that given a problem, what is the best algorithm to choose? Unfortunately there is no exact answer, the performance of each algorithm may vary due to application and environment. However, the following resources are available to help you in this challenge:

Algorithms benchmark

Download links

  • BGSLibrary v1.9.2 with MFC GUI v1.4.2 (x86/x64)

https://github.com/andrewssobral/bgslibrary/releases/download/v1.9.2_x86_mfc_gui/bgslibrary_x86_v1.9.2_with_mfc_gui_v1.4.2.7z

  • BGSLibrary v1.9.2 with Java GUI for Windows 32bits (x86)

https://github.com/andrewssobral/bgslibrary/releases/download/v1.9.2_x86_java_gui/bgslibrary_x86_v1.9.2_with_java_gui_v1.0.4.7z

  • BGSLibrary v1.9.2 with Java GUI for Windows 64bits (x64)

https://github.com/andrewssobral/bgslibrary/releases/download/v1.9.2_x64_java_gui/bgslibrary_x64_v1.9.2_with_java_gui_v1.0.4.7z

MFC BGSLibrary

For Linux and Mac users

Check out latest project source code.

Read instructions in README.txt file.

How to use BGS Library in other C++ code

Download latest project source code, copy package_bgs directory to your project and create config folder (bgslibrary use it to store xml configuration files). For Windows users, a demo project for Visual Studio 2010 is provided.

See Demo.cpp example source code at: https://github.com/andrewssobral/bgslibrary/blob/master/Demo.cpp

How to contribute with BGSLibrary project

Everyone is invited to cooperate with the BGSLibrary project by sending any implementation of background subtraction (BS) algorithms. Please see the following tutorial: https://github.com/andrewssobral/bgslibrary/blob/master/docs/bgslibrary_how_to_contribute.pdf

Full list of BGSLibrary collaborators

I would like to thanks all those who have contributed in some way to the success of this library, especially, the following peoples (in alphabetical order):

Ahmed Elgammal (USA), Antoine Vacavant (France), Benjamin Laugraud (Belgium), Csaba Kertész (Finland), Domenico Bloisi (Italy), Donovan Parks (Canada), Eduardo Barreto Alexandre (Brazil), Fida EL BAF (France), Iñigo Martínez, Jean-Marc Odobez (Switzerland), Jean-Philippe Jodoin (Canada), JIA Pei (China), Jian Yao (China), Hemang Shah, Holger Friedrich, Laurence Bender (Argentina), Lionel Robinault (France), Luca Iocchi (Italy), Luiz Vitor Martinez Cardoso (Brazil), Martin Hofmann, Philipp Tiefenbacher and Gerhard Rigoll (Germany), Rim Trabelsi (Tunisia), Simone Gasparini (France), Stefano Tommesani (Italy), Thierry Bouwmans (France), Vikas Reddy (Australia), Yani Ioannou (Canada), Zhenjie Zhao (China) and Zoran Zivkovic (Netherlands).

Example code

#include <iostream>
#include <cv.h>
#include <highgui.h>

#include "package_bgs/FrameDifferenceBGS.h"

int main(int argc, char **argv)
{
  CvCapture *capture = 0;
  capture = cvCaptureFromCAM(0);

  if(!capture){
    std::cerr << "Cannot initialize video!" << std::endl;
    return -1;
  }

  IBGS *bgs;
  bgs = new FrameDifferenceBGS;

  IplImage *frame;
  while(1)
  {
    frame = cvQueryFrame(capture);
    if(!frame) break;

    cv::Mat img_input(frame);
    cv::imshow("Input", img_input);

    cv::Mat img_mask;
    cv::Mat img_bkgmodel;

    // by default, it shows automatically the foreground mask image
    bgs->process(img_input, img_mask, img_bkgmodel);

    //if(!img_mask.empty())
    //  cv::imshow("Foreground", img_mask);
    //  do something

    if(cvWaitKey(33) >= 0)
		  break;
  }

  delete bgs;

  cvDestroyAllWindows();
  cvReleaseCapture(&capture);

  return 0;
}

Videos

Project Diagram

Java GUI

Release Notes:

  • Version 1.9.2: Added SuBSENSE and LOBSTER algorithms of Pierre-Luc et al. (2014).

  • Version 1.9.1: Added Sigma-Delta background subtraction algorithm (SigmaDeltaBGS) of Manzanera and Richefeu (2004).

  • Version 1.9.0: Added A New Framework for Background Subtraction Using Multiple Cues (SJN_MultiCueBGS) of SeungJong Noh and Moongu Jeon (2012). Added OpenCV 2.4.8 support (all dependencies are linked statically).

  • Version 1.8.0: Added Independent Multimodal Background Subtraction (IMBS) of Domenico Daniele Bloisi (2012). Added Adaptive-Selective Background Model Learning.

  • Version 1.7.0: Added Texture-Based Foreground Detection with MRF of Csaba Kertész (2011). Some improvements and bug fixes, ...

  • Version 1.6.0: Added KDE of A. Elgammal, D. Harwood, L. S. Davis, “Non-parametric Model for Background Subtraction” ECCV'00 (thanks to Elgammal). Added Texture-based Background Subtraction of Marko Heikkila and Matti Pietikainen “A texture-based method for modeling the background and detecting moving objects” PAMI'06. Added OpenCV 2.4.5 support, some improvements and bug fixes, ...

  • Version 1.5.0: Added VuMeter of Yann Goyat, Thierry Chateau, Laurent Malaterre and Laurent Trassoudaine (thanks to Antoine Vacavant). Added OpenCV C++ MFC App (with source code) using BGS Library for Windows users. Added OpenCV 2.4.4 support (all dependencies are linked statically -- bye DLL's), some improvements and bug fixes, ...

  • Version 1.4.0: Added PBAS (Pixel-based adaptive Segmenter) of M. Hofmann, P. Tiefenbacher and G. Rigoll. Added T2F-GMM with MRF of Zhenjie Zhao, Thierry Bouwmans, Xubo Zhang and Yongchun Fang. (thanks to Zhenjie Zhao and Thierry Bouwmans) Added GMG of A. Godbehere, A. Matsukawa, K. Goldberg (opencv native). Added OpenCV 2.4.3 support (all dependencies are linked statically -- bye DLL's), some improvements and bug fixes, ...

  • Version 1.3.0: Added Fuzzy Sugeno and Choquet Integral with Adaptive-Selective Background Model Update (thanks to Thierry Bouwmans) Foreground Mask Analysis upgrade, now with number of True Positives (TP), True Negatives (TN), False Positives (FP), False Negatives (FN), Detection Rate, Precision, Fmeasure, Accuracy, False Negative Rate (FNR), False Positive Rate (FPR), True Positive Rate (TPR) and ROC images (thanks to Thierry Bouwmans) Added OpenCV 2.4 support Some improvements, bug fixes, ...

  • Version 1.2.0: Added Multi-Layer BGS (thanks to Jian Yao and Jean-Marc Odobez) Added Background Subtraction Models from Laurence Bender (Simple Gaussian, Fuzzy Gaussian, Mixture of Gaussians, Adaptive SOM and Fuzzy Adaptive SOM) Added Foreground Mask Analysis (Similarity Measure)

  • Version 1.1.0: Added Type2-Fuzzy GMM UM and UV (thanks to Thierry Bouwmans) Added support to calculate average time of algorithms (see param tictoc in ./config/FrameProcessor.xml)

  • Version 1.0.0: First stable version Added 14 background subtraction algorithms (07 adapted from Donovan Parks)