BGSLibrary Examples

June 12, 2026 ยท View on GitHub

This repository showcases examples of using the BGSLibrary, a comprehensive library for background subtraction in videos and image sequences. These examples are intended to help users understand how to integrate and utilize the BGSLibrary with OpenCV for various background subtraction tasks.

License: MIT Platform: Windows, Linux, OS X OpenCV Algorithms

BGS Library Demo

Requirements

To use the examples in this repository, you must first build and install the BGSLibrary from source. Follow the installation instructions for your platform:

Quick start commands:

git clone --recursive https://github.com/andrewssobral/bgslibrary.git
cd bgslibrary
cmake -S . -B build
cmake --build build -j "$(nproc)"
sudo cmake --install build
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"

By default, the BGSLibrary installs to /usr/local/bin/ for executables, /usr/local/lib/ for libraries, and /usr/local/include/ for include files.

Alternatively, build using Pixi (recommended):

git clone --recursive https://github.com/andrewssobral/bgslibrary.git
cd bgslibrary
pixi shell
pixi run configure
pixi run build
pixi run install

The library and headers will be installed under .pixi/envs/default/.

Note: If you built BGSLibrary using Pixi, remain inside the same Pixi shell when building and running the examples below.

Build and Run Examples

Clone the examples repository and navigate to it:

git clone https://github.com/andrewssobral/bgslibrary-examples-cpp.git
cd bgslibrary-examples-cpp

To build and run an example, such as listing all algorithms:

make bgslibrary_list_algorithms
./bgslibrary_list_algorithms

Uninstall

To uninstall the BGSLibrary, you can use the following commands:

cd bgslibrary/build
cat install_manifest.txt | xargs echo rm | sh
rm -rf /usr/local/include/bgslibrary
rm -rf /usr/local/lib/cmake/BGSLibrary

Configuration

This project uses configuration files stored in the config directory. By default, all files in this directory are ignored except for .gitignore and README.txt, which provides details about the purpose of the directory.

Examples

Included examples demonstrate how to use the BGSLibrary for processing video from a camera, processing a sequence of images, and listing all available algorithms. Each example includes both a source file (.cpp) and a build script (.sh).

For any questions or issues, please refer to the BGSLibrary documentation or submit an issue on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file for details.