Skip to content

A Python-based application implementing and comparing motion detection algorithms, including Frame Difference, Background Subtraction, Optical Flow, and YOLO-integrated object detection. Designed for real-time analysis and research in computer vision and surveillance.

Notifications You must be signed in to change notification settings

OmarAlmusa/motion-detection-app-python

Repository files navigation

Motion Detection Using Frame Difference, Background Subtraction, Optical Flow, and Object Detection

main interface

Introduction

Motion detection is a critical capability in fields such as surveillance, robotics, and computer vision. It involves identifying moving objects in video sequences and serves as the foundation for many advanced applications, from geospatial analysis to autonomous systems.

This project explores various motion detection methods, including:

  • Frame Difference
  • Background Subtraction
  • Optical Flow (Sparse and Dense)
  • Background Subtraction combined with Object Detection (MOG + YOLO)

The goal is to evaluate their strengths, limitations, and real-world applications while showcasing their implementation and comparative analysis.


Methods

Frame Difference

frame difference interface


  • Compares consecutive video frames pixel by pixel to identify changes.
  • Strengths: Simple and computationally efficient.
  • Weaknesses: Sensitive to noise, struggles with complex backgrounds.

Background Subtraction

  • Models the static background scene to identify moving objects.
  • Techniques include:
    • Mixture of Gaussians (MOG)
    • K-Nearest Neighbors (KNN)
  • Strengths: Effective in dynamic environments.
  • Weaknesses: Sensitive to shadows and lighting changes.

Optical Flow

optical flow interface


  • Computes motion vectors for pixels between consecutive frames.
    • Sparse Optical Flow: Focuses on key points (e.g., corners, edges).
    • Dense Optical Flow: Provides motion vectors for every pixel.
  • Strengths: Detailed motion understanding.
  • Weaknesses: High computational complexity, sensitive to noise.

Background Subtraction + Object Detection

Background Subtraction + Object Detection


  • Combines MOG background subtraction with YOLOv8 object detection.
  • Detects and classifies moving objects.
  • Strengths: High accuracy, robust against complex scenarios.
  • Weaknesses: Computationally intensive, challenges with fast motion.

Comparisons

Method Advantages Limitations
Frame Differencing Simple and efficient Sensitive to noise, poor with complex scenes
Background Subtraction Robust for dynamic environments Requires accurate background modeling
Optical Flow Comprehensive motion analysis Computationally expensive, sensitive to noise
MOG + YOLO High accuracy, robust classification Resource-intensive, struggles with rapid motion

Results and Observations

  • Frame Differencing: Effective for simple, static backgrounds but prone to errors in complex scenes.
  • Background Subtraction: Offers improved accuracy but detects shadows and lighting changes as motion.
  • Optical Flow:
    • Sparse: Limited to key points; suitable for coarse analysis.
    • Dense: Highly detailed but requires significant computational resources.
  • MOG + YOLO: Best performance in detecting and classifying moving objects; however, requires GPU acceleration for real-time applications.

Requirements

  • Python 3.x
  • OpenCV (with CUDA support for Dense Optical Flow)
  • YOLOv8 by Ultralytics
  • Pytorch with CUDA support

Usage

  1. Clone this repository:

    git clone https://github.com/OmarAlmusa/motion-detection-app-python.git
    cd motion-detection
  2. Install the required libraries:

    pip install -r requirements.txt
  3. Run the program as following:

    python main_interface.py

References

This project is based on extensive research and implementation of algorithms and techniques documented in:

  • OpenCV Documentation
  • Research papers on motion detection
  • NVIDIA VPI Documentation
  • Ultralytics YOLOv8
  • Customtkinter

Additional Information

More information about the project can be found in docx file provided in the repo.

About

A Python-based application implementing and comparing motion detection algorithms, including Frame Difference, Background Subtraction, Optical Flow, and YOLO-integrated object detection. Designed for real-time analysis and research in computer vision and surveillance.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages