Frame differencing
We know that we cannot keep a static background image pattern that can be used to detect objects. One of the ways to fix this would be by using frame differencing. It is one of the simplest techniques we can use to see what parts of the video are moving. When we consider a live video stream, the difference between successive frames gives a lot of information. The concept is fairly straightforward! We just take the difference between successive frames and display the differences between them.
If I move my laptop rapidly, we can see something like this:
Instead of the laptop, let's move the object and see what happens. If I rapidly shake my head, it will look something like this:
As you can see from the previous images, only the moving parts of the video get highlighted. This gives us a good starting point to see what areas are moving in the video. Let's look at the function to compute the frame differences:
Mat frameDiff(Mat prevFrame, Mat curFrame, Mat nextFrame) { ...