Skip to content
Fernando Alzueta edited this page Sep 11, 2024 · 4 revisions

Motion Detection with OpenCV

Welcome to the Motion Detection with OpenCV project! This project implements a motion detection system using the OpenCV library in Python. When motion is detected, the system records a 17-second video.

Features

  • Real-time motion detection
  • Video recording upon motion detection
  • Adjustable parameters for contour area and video duration

Getting Started

Requirements

  • Python >= 3.9
  • OpenCV libraries

Installation

  1. Clone the repository:

git clone https://github.com/devluisrodrigues/motion-detection

cd motion-detection

  1. Install the dependencies:

pip install -r requirements.txt

Usage

  1. Run the script motion_detection.py:

python motion_detection.py

  1. The script will open your device's default camera and start monitoring for motion. When motion is detected, a video will be recorded and saved in the current directory.

Parameters

You can adjust the following parameters in the script motion_detection.py:

  • MIN_CONTOUR_AREA: Minimum contour area to consider as motion. Default is 15.
  • VIDEO_DURATION: Duration of the video to be recorded after detecting motion. Default is 17 seconds.

How It Works

  1. The script captures frames from the camera in real-time.
  2. Converts the frames to grayscale and applies Gaussian blur.
  3. Compares the current frame with the previous frame to detect changes.
  4. If the change is significant (based on contour area), a video is recorded.
  5. The video is saved in AVI format with a timestamp in the filename.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Clone this wiki locally