Frame differencing
Frame differencing is one of the simplest techniques that can be used to identify the moving parts in a video. When we are looking at a live video stream, the differences between consecutive frames captured from the stream gives us a lot of information. Let's see how we can take the differences between consecutive frames and display the differences. The code in this section requires an attached camera, so make sure you have a camera on your machine.
Create a new Python file and import the following package:
import cv2
Define a function to compute the frame differences. Start by computing the difference between the current frame and the next frame:
# Compute the frame differences def frame_diff(prev_frame, cur_frame, next_frame): # Difference between the current frame and the next frame diff_frames_1 = cv2.absdiff(next_frame, cur_frame)
Compute the difference between the current frame and the previous frame:
# Difference between the current frame and...