In this article, we discuss the concept of a moving average . The moving average of the function is used to separate the foreground from the background. In this concept, a video sequence is analyzed over a specific set of frames. During this sequence of frames, a moving average is calculated for the current frame and previous frames. This gives us a background model, and any new object introduced during the video sequence becomes part of the foreground. Then the current frame contains the newly entered object with the background. It then calculates the absolute difference between the background model (which is a function of time) and the current frame (which is the newly entered object). The moving average is calculated using the equation below:
How does the moving average method work?
The purpose of the program is to detect active objects from the difference obtained from the keyframe and the current frame. We continue to feed each frame to this function, and the function continues to find the average of all frames. We then calculate the absolute difference between frames.
Function used — cv2.accumulate>Weighted () .
cv2.accumulateWeighted (src, dst, alpha)
Parameters passed to this function:
As we can see below, the hand is blocking the background image.
T Now we shake the foreground object, i.e. our hand. We start to wave our hand.
The Moving Average shows the background below, and the Moving Average with alpha 0.02 perceives it as a transparent hand with the main emphasis on the background.
Alternatively we can use cv.RunningAvg () for that same task with parameters that have the same meaning as cv2.accumulateweighted () parameters.
cv.RunningAvg (image, acc, alpha)