Frame differencing
This is, possibly, the simplest technique 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 us a lot of information. The concept is fairly straightforward! We just take the difference between successive frames and display the differences.
If we move rapidly from left to right, we will see something like this:
As you can see from the previous image, only the moving parts in the video get highlighted. This gives us a good starting point to see what areas are moving in the video. Here is the code to do this:
import cv2 # Compute the frame difference def frame_diff(prev_frame, cur_frame, next_frame): # Absolute difference between current frame and next frame diff_frames1 = cv2.absdiff(next_frame, cur_frame) # Absolute difference between current frame and # previous frame diff_frames2 = cv2.absdiff(cur_frame, prev_frame) # Return the result of bitwise 'AND...