📚 Course contents

AI & Computer Vision, lesson 9 of 52

Motion Detection & Background Subtraction

beginner20 min readFull course

Introduction

A security camera doesn't know what a burglar looks like. It just notices that something in the picture changed. Today you'll build that: first by subtracting one frame from the last, then with a smarter method that learns what the empty scene looks like. You'll finish with a motion alarm that records only while something is moving.

By the end of this lesson you'll be able to:

  • Detect movement by frame differencing: subtract one frame from the last
  • Use cv2.createBackgroundSubtractorMOG2 and explain what it learns
  • Turn a motion mask into boxes with contours
  • Build a motion alarm with a minimum area and a cool-down time
  • Save frames only while something is moving
  • Explain what moving shadows, camera shake and light changes do to motion detection
Motion Detection & Background Subtraction | Electronics Simplified