This project demonstrates a basic motion detection system using OpenCV and Python. It captures video from a camera, processes the frames to detect moving objects, and highlights detected motion areas in real-time. π
- πΉ Capture video feed from the webcam.
- π¨ Convert frames to grayscale and apply Gaussian blur for noise reduction.
- π Detect motion by comparing the current frame with the first frame.
- π² Highlight moving objects with bounding rectangles.
- π Display status text indicating whether motion is detected.
- β Press
qto quit the application.
- Python 3.x π
- OpenCV (
cv2) πΌοΈ - Imutils π§
- Time module (standard Python library) β°
Install required libraries using pip:
pip install opencv-python imutilsRun the script to start the motion detection:
python motion_detection.pyβοΈ How It Works
π₯ The first frame is captured and used as a reference.
π€ Each new frame is converted to grayscale and blurred.
β The absolute difference between the current frame and the reference frame is calculated.
β« Thresholding and dilation are applied to highlight differences.
π Contours are detected in the thresholded image.
β If contours exceed a minimum area, bounding boxes are drawn, and motion is detected.
πΊ The video feed with detected motion highlighted is displayed.