Background Subtraction is one of the major Image Processing tasks. It is used in various Image Processing applications like Image Segmentation, Object Detection, etc. OpenCV provides us 3 types of Background Subtraction algorithms:-
Normally, we can perform background Subtraction using matrix subtraction, i.e, just subtracting the static frame from the video. But this has a lot of drawbacks. It is a very less efficient algorithm for Background subtraction because it does not update itself. This problem is being handled by the Background Subtraction algorithms provided by OpenCV.
To use BackgroundSubtractorMOG we can use
Then we can apply it using the “apply” method on each frame of the video. Consider the below example for a better understanding of the topic.
In the previous subtractor worked fairly well but in real-world situations, there is also a presence of shadows. In BackgroundSubtractorMOG2, we can also detect shadows and in the output of the following code, it’s clearly seen. To apply BackgroundSubtractorMOG2, use
This algorithm combines statistical background image estimation and per-pixel Bayesian segmentation. It employs a probabilistic foreground segmentation algorithm that identifies possible foreground objects using Bayesian inference. To use BackgroundSubtractorGMG, use
Note: We will get a black window during first few frames.
- Python | Background subtraction using OpenCV
- Background subtraction - OpenCV
- Arithmetic Operations on Images using OpenCV | Set-1 (Addition and Subtraction)
- 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 Python Program to blur an image
- Cartooning an Image using OpenCV - Python
- Opencv Python program for Face Detection
- Real-Time Edge Detection using OpenCV in Python | Canny edge detection method
- OpenCV Python Program to analyze an image using Histogram
- Detection of a specific color(blue here) using OpenCV with Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.