This shows Image Processing abilities to build a motion detection algorithm that alarms you when you have an unwanted visitor in camera frame.
-
- Get the live video feed from your webcam
-
- Fix a scene (the place you want to monitor) and store it as a reference background image
- Store the first frame as the reference background frame
-
- For every frame, check if there is any unwanted object inside the scene you are monitoring
- Use Background Subtraction concept (cv2.absdiff( ))
- Subtract the current frame from the reference background image(frame) to see the changes in the scene
- If there is enormous amount of pixels distrubed in the subtraction result image < 81B6 ul dir="auto">
- unwanted visitor (place is unsafe --> alarm the authorities)
- If there is no enormous amount of pixels distrubed in the subtraction result image
- no unwanted visitor (place is safe)
- Output the text "UNSAFE" in red color on the top right of the frame when there is an intruder in the scene.
- Save the live feed
- OpenCV (
cv2
) - time
-
Install the required packages:
pip install opencv-python
-
Clone this repository.
- Run the
Thief_Detector.ipynb
notebook. - The script will capture video from your default webcam.
- It will display a window showing the video feed with "UNSAFE" text when motion is detected.
- The video feed will also be saved to a file named
thief_detector_output.avi
. - Press 'q' to quit.
Initializes and returns the video capture object from the webcam.
Captures the initial background frame from the video feed, converts it to grayscale, and applies Gaussian blur for noise reduction.
Computes the absolute difference between the current frame and the reference background frame.
Applies a threshold to the difference image to create a binary image highlighting motion.
Finds the contours (boundaries of moving objects) in the thresholded image.
Draws a rectangle around detected motion and adds "UNSAFE" text to the frame if significant motion is detected.
Displays the processed frame and saves it to a video file. It also checks for the 'q' key to quit.
Releases the video capture and writer objects, and closes all windows.
Main function that runs the motion detection process.