This simple C++ program uses OpenCV to perform motion detection using a webcam or IP camera stream. It captures consecutive frames, calculates the absolute difference between them, and applies a threshold to identify motion.
- OpenCV library installed. You can install it using the following command:
sudo apt-get install libopencv-dev
-
Clone the repository:
git clone https://github.com/real0x0a1/Webcam-Motion-Sensor.git
-
Navigate to the project directory:
cd Webcam-Motion-Sensor
-
Compile the code:
g++ WebcamMotionSensor.cpp -o WebcamMotionSensor `pkg-config --cflags --libs opencv`
-
Run the executable:
./WebcamMotionSensor
Note: If you're using an IP camera, replace the URL in the
cv::VideoCapture
constructor with your camera's IP address. -
Press the 'ESC' key to exit the application.
- Real-time motion detection using OpenCV.
- Supports both webcam and IP camera streams.
- If the program fails to connect to the camera, check the camera's IP address or ensure it is correctly connected.
- Make sure the OpenCV library is properly installed.
To run this program:
- Make sure you have a C compiler installed on your computer.
- Copy the code into a file with a
.cpp
extension, for example,WebcamMotionSensor.cpp
. - Open a terminal or command prompt and navigate to the directory where your file is located.
- Compile the program by entering:
g++ WebcamMotionSensor.cpp -o WebcamMotionSensor
- Run the compiled program:
./WebcamMotionSensor
Or you can run this program also using:
make WebcamMotionSensor