From 795199cad64b287bab28434e08b39b877206b203 Mon Sep 17 00:00:00 2001 From: iamdevdhanush Date: Mon, 5 Jan 2026 09:02:41 +0000 Subject: [PATCH 1/2] Added Motion Detection Project --- Motion-Detection | 1 + 1 file changed, 1 insertion(+) create mode 160000 Motion-Detection diff --git a/Motion-Detection b/Motion-Detection new file mode 160000 index 0000000..e4011e7 --- /dev/null +++ b/Motion-Detection @@ -0,0 +1 @@ +Subproject commit e4011e7254c239ba2286c6c300c633ff52045f9e From d3ada1e750c2d31d9b964ba0c7cd7adaf376f0e6 Mon Sep 17 00:00:00 2001 From: iamdevdhanush Date: Mon, 5 Jan 2026 09:39:29 +0000 Subject: [PATCH 2/2] Convert Motion-Detection from submodule to normal folder --- Motion-Detection | 1 - Motion-Detection/OpenCvPROJECT.py | 52 ++++++++++++++++++++++++++++ Motion-Detection/README.md | 57 +++++++++++++++++++++++++++++++ 3 files changed, 109 insertions(+), 1 deletion(-) delete mode 160000 Motion-Detection create mode 100644 Motion-Detection/OpenCvPROJECT.py create mode 100644 Motion-Detection/README.md diff --git a/Motion-Detection b/Motion-Detection deleted file mode 160000 index e4011e7..0000000 --- a/Motion-Detection +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e4011e7254c239ba2286c6c300c633ff52045f9e diff --git a/Motion-Detection/OpenCvPROJECT.py b/Motion-Detection/OpenCvPROJECT.py new file mode 100644 index 0000000..404de24 --- /dev/null +++ b/Motion-Detection/OpenCvPROJECT.py @@ -0,0 +1,52 @@ +import cv2 +import time +import imutils + +cam = cv2.VideoCapture(0) +time.sleep(0) +firstFrame = None +area = 500 +frameUpdateInterval = 100 +frameCount = 0 + +while True: + ret, img = cam.read() + if not ret: + break + + text = "Normal" + img = imutils.resize(img, width=600) + grayImg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) + gaussianImg = cv2.GaussianBlur(grayImg, (21, 21), 0) + + if firstFrame is None or frameCount % frameUpdateInterval == 0: + firstFrame = gaussianImg + frameCount = 0 + + frameCount += 1 + + imgDiff = cv2.absdiff(firstFrame, gaussianImg) + + threshImg = cv2.threshold(imgDiff, 25, 255, cv2.THRESH_BINARY)[1] + threshImg = cv2.dilate(threshImg, None, iterations=2) + + cnts = cv2.findContours(threshImg.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) + cnts = imutils.grab_contours(cnts) + + for c in cnts: + if cv2.contourArea(c) < area: + continue + + (x, y, w, h) = cv2.boundingRect(c) + cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2) + text = "Moving Object detected" + + cv2.putText(img, text, (10, 20), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2) + cv2.imshow("cameraFeed", img) + + key = cv2.waitKey(1) & 0xFF + if key == ord("q"): + break + +cam.release() +cv2.destroyAllWindows() diff --git a/Motion-Detection/README.md b/Motion-Detection/README.md new file mode 100644 index 0000000..485594a --- /dev/null +++ b/Motion-Detection/README.md @@ -0,0 +1,57 @@ +# 🎥 Motion Detection Using OpenCV 🕵️‍♂️ + +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. 🚀 + +--- + +## ✨ Features + +- 📹 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 **`q`** to quit the application. + +--- + +## 🛠️ Requirements + +- Python 3.x 🐍 +- OpenCV (`cv2`) 🖼️ +- Imutils 🔧 +- Time module (standard Python library) ⏰ + +--- + +## 📦 Installation + +Install required libraries using pip: + +```bash +pip install opencv-python imutils +``` + +▶️ Usage + +Run the script to start the motion detection: + +```bash +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.