Background subtraction is a way of eliminating the background from image. To achieve this we extract the moving foreground from the static background.
Background Subtraction has several use cases in everyday life, It is being used for object segmentation, security enhancement, pedestrian tracking, counting the number of visitors, number of vehicles in traffic etc. It is able to learn and identify the foreground mask.
In OpenCV we have 3 algorithms to do this operation –
BackgroundSubtractorMOG – It is a Gaussian Mixture-based Background/Foreground Segmentation Algorithm.
BackgroundSubtractorMOG2 – It is also a Gaussian Mixture-based Background/Foreground Segmentation Algorithm. It provides better adaptability to varying scenes due illumination changes etc.
BackgroundSubtractorGMG – This algorithm combines statistical background image estimation and per-pixel Bayesian segmentation.
How to apply OpenCV in-built functions for background subtraction –
Step #1 – Create an object to signify the algorithm we are using for background subtraction.
Step #2 – Apply
backgroundsubtractor.apply() function on image.
We can see that there is a lot of noise in the resultant image for
BackgroundSubtractorGMG, hence it is always preferred to use morphological transformation to the result to remove the noises.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python | Background subtraction using OpenCV
- Python OpenCV - Background Subtraction
- Arithmetic Operations on Images using OpenCV | Set-1 (Addition and Subtraction)
- Project Idea | Motion detection using Background Subtraction Techniques
- Background Subtraction in an Image using Concept of Running Average
- OpenCV - Facial Landmarks and Face Detection using dlib and OpenCV
- Transition from OpenCV 2 to OpenCV 3.x
- Python | Subtraction of dictionaries
- Python | How to get Subtraction of tuples
- Python | Mutual tuple subtraction in list
- Python | Nth tuple index Subtraction by K
- Python program for addition and subtraction of complex numbers
- Python | Nested Tuples Subtraction
- Addition and Subtraction on TimeDelta objects using Pandas - Python
- Perform addition and subtraction using CherryPy
- OpenCV C++ Program to play a video
- OpenCV C++ Program to blur a Video
- OpenCV C++ Program to create a single colored blank image
- OpenCV C++ Program to blur an image
- OpenCV Python Program to blur an image
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.