Skip to content

andrewssobral/bgslibrary

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BGSLibrary

BGSLibrary: A Background Subtraction Library

Release License: GPL v3 Platform: Windows, Linux, OS X OpenCV Wrapper: Python, MATLAB Algorithms Ask DeepWiki

Introduction

The BGSLibrary (Background Subtraction Library) is a comprehensive C++ framework designed for background subtraction in computer vision applications, particularly for detecting moving objects in video streams. It provides an easy-to-use and extensible platform for researchers and developers to experiment with and implement various background subtraction techniques.

Library Version

3.3.0 (see Build Status and Release Notes for more info)

Background and Development

The BGSLibrary was developed in early 2012 by Andrews Cordolino Sobral as a C++ framework with wrappers available for Python, Java, and MATLAB. It aims to facilitate foreground-background separation in videos using the OpenCV library.

Compatibility

The library is compatible with OpenCV versions 2.4.x, 3.x, and 4.x. It can be compiled and used on Windows, Linux, and Mac OS X systems.

Licensing

The library's source code is available under the MIT license, making it free for both academic and commercial use.

Getting started

Ask DeepWiki

#include <iostream>
#include <algorithm>
#include <iterator>
#include <vector>

// Include the OpenCV and BGSLibrary libraries
#include <opencv2/opencv.hpp>
#include <bgslibrary/algorithms/algorithms.h>

int main( int argc, char** argv )
{
    // Gets the names of the background subtraction algorithms registered in the BGSLibrary factory
    auto algorithmsName = BGS_Factory::Instance()->GetRegisteredAlgorithmsName();

    // Displays the number of available background subtraction algorithms in the BGSLibrary
    std::cout << "Number of available algorithms: " << algorithmsName.size() << std::endl;

    // Displays the list of available background subtraction algorithms in the BGSLibrary
    std::cout << "List of available algorithms:" << std::endl;
    std::copy(algorithmsName.begin(), algorithmsName.end(), std::ostream_iterator<std::string>(std::cout, "\n"));

    // Returns 0 to indicate that the execution was successful
    return 0;
}

Installation instructions

You can either install BGSLibrary via pre-built binary package or build it from source.

Supported Compilers:

  • GCC 4.8 and above
  • Clang 3.4 and above
  • MSVC 2015, 2017, 2019 or newer

Other compilers might work, but are not officially supported. The bgslibrary requires some features from the ISO C++ 2014 standard.

🚀 Build Using Pixi (Recommended)

Pixi provides a clean and reproducible way to build BGSLibrary with no manual OpenCV installation. It works on macOS, Linux, and Windows (WSL recommended).

0. Install Pixi
curl -fsSL https://pixi.sh/install.sh | sh

Restart your terminal after installation.

1. Create a Pixi workspace

Inside the bgslibrary repository:

pixi init .

Add required dependencies:

pixi add opencv cmake ninja compilers pkg-config

Pixi will generate a pixi.toml with:

  • OpenCV (C++ + Python bindings)
  • C/C++ compilers
  • CMake + Ninja
  • pkg-config
2. Add Pixi build tasks

Append this block to your pixi.toml:

[tasks]
# Core build tasks
configure = "cmake -S . -B build -G Ninja"
build = "cmake --build build"
clean = "rm -rf build"

# Examples tasks
configure_examples = "cmake -S examples -B examples/build"
build_examples = { cmd = "cmake --build examples/build", depends-on = ["configure_examples"] }
clean_examples = "rm -rf examples/build"

# Combined tasks
rebuild = { cmd = "echo 'Rebuild complete'", depends-on = ["clean", "configure", "build"] }
rebuild_all = { cmd = "echo 'Full rebuild complete'", depends-on = ["clean", "clean_examples", "rebuild", "build_examples"] }

# Run tasks
run = "./build/bgslibrary --use_cam --camera=0"
run_bgs_demo = "./examples/build/bgs_demo"
run_bgs_demo2 = "./examples/build/bgs_demo2"

# Development helpers
install = { cmd = "cmake --install build --prefix .pixi/envs/default", depends-on = ["build"] }

This configuration provides granular control over the build process with separate tasks for cleaning, configuring, and building.

3. Activate the Pixi environment
pixi shell
4. Configure the build
pixi run configure
5. Build bgslibrary
pixi run build

This generates:

  • build/bgslibrary
  • build/libbgslibrary_core.*
6. Build C++ examples (optional)
pixi run build_examples

This produces:

  • examples/build/bgs_demo
  • examples/build/bgs_demo2
7. Run bgslibrary

Camera demo:

pixi run run

Demo using a video file:

pixi run run_bgs_demo

Demo using an image sequence:

pixi run run_bgs_demo2
8. Install bgslibrary into the Pixi environment (optional)
pixi run install

The library and headers go into .pixi/envs/default/

You can then use bgslibrary from other CMake projects in the same environment, for example:

find_package(BGSLibrary REQUIRED)
9. Clean and rebuild

To clean build artifacts:

pixi run clean          # Clean main build
pixi run clean_examples # Clean examples

To rebuild everything from scratch:

pixi run rebuild     # Rebuild main project
pixi run rebuild_all # Rebuild main project + examples

These tasks automatically handle dependencies, ensuring a consistent build state.

🛠 Build Using CMake (Classic Method)

Graphical User Interface

Wrappers

Usage examples

More

Algorithm compatibility across OpenCV versions

Algorithm OpenCV < 3.0 (42) 3.0 <= OpenCV <= 3.4.7 (41) 3.4.7 < OpenCV < 4.0 (39) OpenCV >= 4.0 (26)
AdaptiveBackgroundLearning ✔️ ✔️ ✔️ ✔️
AdaptiveSelectiveBackgroundLearning ✔️ ✔️ ✔️ ✔️
CodeBook ✔️ ✔️ ✔️ ✔️
DPAdaptiveMedian ✔️ ✔️ ✔️
DPEigenbackground ✔️ ✔️ ✔️
DPGrimsonGMM ✔️ ✔️ ✔️
DPMean ✔️ ✔️ ✔️
DPPratiMediod ✔️ ✔️ ✔️
DPTexture ✔️ ✔️ ✔️
DPWrenGA ✔️ ✔️ ✔️
DPZivkovicAGMM ✔️ ✔️ ✔️
FrameDifference ✔️ ✔️ ✔️ ✔️
FuzzyChoquetIntegral ✔️ ✔️ ✔️ ✔️
FuzzySugenoIntegral ✔️ ✔️ ✔️ ✔️
GMG ✔️
IndependentMultimodal ✔️ ✔️ ✔️ ✔️
KDE ✔️ ✔️ ✔️ ✔️
KNN ✔️ ✔️ ✔️
LBAdaptiveSOM ✔️ ✔️ ✔️ ✔️
LBFuzzyAdaptiveSOM ✔️ ✔️ ✔️ ✔️
LBFuzzyGaussian ✔️ ✔️ ✔️ ✔️
LBMixtureOfGaussians ✔️ ✔️ ✔️ ✔️
LBP_MRF ✔️ ✔️
LBSimpleGaussian ✔️ ✔️ ✔️ ✔️
LOBSTER ✔️ ✔️ ✔️ ✔️
MixtureOfGaussianV1 ✔️
MixtureOfGaussianV2 ✔️ ✔️ ✔️ ✔️
MultiCue ✔️ ✔️ ✔️
MultiLayer ✔️ ✔️
PAWCS ✔️ ✔️ ✔️ ✔️
PixelBasedAdaptiveSegmenter ✔️ ✔️ ✔️ ✔️
SigmaDelta ✔️ ✔️ ✔️ ✔️
StaticFrameDifference ✔️ ✔️ ✔️ ✔️
SuBSENSE ✔️ ✔️ ✔️ ✔️
T2FGMM_UM ✔️ ✔️ ✔️
T2FGMM_UV ✔️ ✔️ ✔️
T2FMRF_UM ✔️ ✔️ ✔️
T2FMRF_UV ✔️ ✔️ ✔️
TwoPoints ✔️ ✔️ ✔️ ✔️
ViBe ✔️ ✔️ ✔️ ✔️
VuMeter ✔️ ✔️ ✔️ ✔️
WeightedMovingMean ✔️ ✔️ ✔️ ✔️
WeightedMovingVariance ✔️ ✔️ ✔️ ✔️

Stargazers over time

Stargazers over time

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}
}

A 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},
}

References

  • 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 containing an 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).

Some algorithms of the BGSLibrary were used successfully in the 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)

Videos

About

A C++ Background Subtraction Library with wrappers for Python, MATLAB, Java and GUI on QT

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Contributors 21