Premium

Security Camera System

Counting HOW MANY pixels changed can't tell a cloud passing from a person walking through — counting WHERE they changed can.

  • Raspberry Pi
  • Python
  • OpenCV

About this project

A motion-triggered monitor: watch a video stream frame by frame, decide whether something genuinely moved, and write a real, timestamped event log when it does — optionally naming who it saw, using a face-recognition model you trained yourself. Written for a Raspberry Pi + Camera Module, but the detection logic itself is plain OpenCV against any video source: a webcam, a video file, or a Pi camera.

Naive motion detection counts how many pixels changed between two frames and alerts once that count crosses a threshold — which false-alarms constantly on lighting changes, because a cloud passing or auto-exposure adjusting shifts every pixel in the frame by a small amount, tripping the same total-count threshold as a real, spatially concentrated object. This project fixes it with contour detection: after thresholding the frame difference, it finds CONNECTED regions of change and only alerts when at least one region's area clears a calibrated minimum — a lighting change produces no region that large, real motion does. Proven with real synthetic frame sequences for both scenarios, and honestly limited: an abrupt, large lighting jump (a light switching on, not gradual auto-exposure) still fools the fix, and the README says exactly why and what a more complete solution would need.

What you will learn

  • Understand why counting total changed pixels alone false-alarms on lighting changes
  • Use contour detection to distinguish a spatially concentrated change from a frame-wide one
  • Calibrate a real minimum contour area from measured synthetic scenarios, not a guessed number
  • Recognise and honestly document a real limitation instead of overclaiming a fix's scope
  • Reuse the same OpenCV motion-detection logic against a webcam, a video file, or a Pi camera unchanged

Before you start

  • Python basics — functions, and reading OpenCV's array-based frame data
  • Python 3.10+ — no camera or Raspberry Pi needed to install, verify, or read this project
  • A webcam, video file, or Raspberry Pi Camera Module for live use

New to Raspberry Pi? The free Raspberry Pi course covers everything this project assumes.

Academic integrity notice

These projects are provided for learning, experimentation and reference. Understand the code, modify it for your own requirements, and acknowledge external work according to your institution’s academic policies. Priodemy does not supply work to be submitted as your own.