Skip to content

Real-time motion detection and tracking pipeline using OpenCV (C++).

License

Notifications You must be signed in to change notification settings

Moncef-Bj/realtime-motion-detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Real-Time Motion Detection System

A high-performance motion detection application built with C++ and OpenCV. Uses the MOG2 (Mixture of Gaussians) background subtraction algorithm for professional-grade motion detection.

C++ OpenCV Platform License


Features

  • MOG2 Algorithm - Professional background subtraction for accurate detection
  • Real-time Processing - Low latency video processing (~30 FPS)
  • Multi-View Display - See original, mask, and detection simultaneously
  • Adjustable Sensitivity - Fine-tune detection with keyboard controls
  • Screenshot Capture - Save frames with detected motion
  • Timestamp Overlay - Security camera style timestamp
  • FPS Counter - Real-time performance monitoring
  • Color-Coded Alerts - Green/Orange/Red based on motion intensity

Quick Start

Prerequisites

  • C++ compiler (GCC/MinGW)
  • OpenCV 4.x
  • Qt6 (for GUI)

Installation (Windows with MSYS2)

  1. Clone the repository
git clone https://github.com/Moncef-Bj/realtime-motion-detection.git
cd realtime-motion-detection
  1. Compile
g++ src/main.cpp -o motion_detection.exe -Iinclude -IC:/msys64/mingw64/include/opencv4 -LC:/msys64/mingw64/lib -lopencv_core -lopencv_highgui -lopencv_videoio -lopencv_imgproc -lopencv_video -lopencv_imgcodecs
  1. Run
./motion_detection.exe

Controls

Key Action
Q Quit application
R Reset background model
+ / = Increase sensitivity
- Decrease sensitivity
S Save screenshot
M Toggle multi-view mode

How It Works

  1. Background Subtraction (MOG2) - Learns the static background and identifies moving foreground
  2. Thresholding - Removes shadows and noise from the motion mask
  3. Morphological Operations - Cleans up the mask
  4. Contour Detection - Finds the boundaries of motion areas
  5. Visualization - Draws bounding boxes with color-coded alerts

Project Structure

realtime-motion-detection/
├── README.md
├── LICENSE
├── include/
│   └── motion_detector.hpp
└── src/
    └── main.cpp

License

MIT License - see LICENSE for details.

About

Real-time motion detection and tracking pipeline using OpenCV (C++).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages