← Back to Portfolio
Motion Detection Graph

Personal Project

Motion Detection Graph

OpenCVPythonPandasBokeh

Overview

A motion detection tool that captures webcam frames, detects movement by comparing frames against a static background using OpenCV, and plots an interactive time-series graph showing the duration and frequency of detected presence over a session.


Role

Sole Engineer


Problem

Understanding how long a subject is present in a camera frame — and visualising that over time — has applications in attention tracking, occupancy monitoring, and basic behavioural analysis. The project explored building a lightweight tool for logging motion intervals and visualizing the data clearly.

Solution

A Python script captures webcam frames via OpenCV VideoCapture, applies background subtraction and contour detection to identify motion, and logs the start and end timestamps of each motion event. The data is processed using Pandas and an interactive HTML time-series graph is generated using Bokeh to visualize the presence duration.


Architecture

A Python loop captures and processes frames with OpenCV to log motion events, while a separate data processing phase uses Pandas to format the timestamps and Bokeh to render an interactive HTML plot.

Key Design Decisions

  • OpenCV VideoCapture for real-time webcam frame acquisition at configurable frame rates
  • Background subtraction using frame differencing and Gaussian blur to reduce noise and detection artifacts
  • Frame pre-processing pipeline: grayscale conversion and histogram equalisation for detection robustness
  • Timestamp logging for the start and end of continuous motion events, exported to a CSV file
  • Data manipulation and formatting using Pandas DataFrames
  • Interactive time-series graphing using Bokeh with hover tools to display precise event timings
  • Detection sensitivity configurable via minimum contour area thresholds

Challenges

  • Handling sudden lighting changes that could trigger false positive motion events
  • Tuning the Gaussian blur and contour area thresholds to filter out background noise while reliably detecting subjects
  • Ensuring the start and end timestamps of motion events are correctly paired and appended to the dataset, especially during rapid entry and exit
  • Formatting datetime objects correctly so that the Bokeh figure can accurately plot the start and end times on a continuous x-axis

Impact

  • Built a fully functional motion detection and visualization tool using standard Python data science and computer vision libraries
  • Demonstrated practical application of classical computer vision for security and monitoring use cases
  • Created an interactive, exportable HTML graph that allows users to easily analyze motion data post-capture