Motion detection works by comparing one video frame to another
taken previously. If they differ by more than a minimal amount,
motion was detected. This technique is called Image Subtraction.
Here's the complete algorithm:
- Capture a frame (frame1) and convert it to grayscale.
- Skip nS frames (nS is a param, set by nSkippedFrames).
- Capture a second frame (frame2) and convert it to grayscale.
- delta = abs(frame1 - frame2).
- nP is number of pixels in delta >= t (t is a param,
set by pctIllumChange).
- If nP >= N, motionExists = true, else motionExists = false. (N is a param,
set by nPixelsChanged.)
- Location of motion is CG of pixels in delta >= t.