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.
- 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
- C++ compiler (GCC/MinGW)
- OpenCV 4.x
- Qt6 (for GUI)
- Clone the repository
git clone https://github.com/Moncef-Bj/realtime-motion-detection.git
cd realtime-motion-detection- 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- Run
./motion_detection.exe| Key | Action |
|---|---|
Q |
Quit application |
R |
Reset background model |
+ / = |
Increase sensitivity |
- |
Decrease sensitivity |
S |
Save screenshot |
M |
Toggle multi-view mode |
- Background Subtraction (MOG2) - Learns the static background and identifies moving foreground
- Thresholding - Removes shadows and noise from the motion mask
- Morphological Operations - Cleans up the mask
- Contour Detection - Finds the boundaries of motion areas
- Visualization - Draws bounding boxes with color-coded alerts
realtime-motion-detection/
├── README.md
├── LICENSE
├── include/
│ └── motion_detector.hpp
└── src/
└── main.cpp
MIT License - see LICENSE for details.