The project uses OpenCV 2.4 to detect any motion in a video stream from a camera, when a movement is detected, the frame is saved as an image file. Its part of Head First C's C Lab 2(opencv).
- OpenCV 2.4 (later versions don't support C)
- GCC / Linux
-
Install dependencies:
sudo apt-get update sudo apt-get install build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev
-
Download and install OpenCV 2.4:
git clone -b 2.4 https://github.com/opencv/opencv.git cd opencv
mkdir build cd build cmake ..
make -j4 sudo make install sudo ldconfig
-
Clone this repository:
git clone https://github.com/Numbers0689/opencv-motion-detection cd opencv-motion-detection
-
Run the Makefile:
make
-
Run the program:
./detect
- The program captures video from the default camera.
- It calculates the dense optical flow between consecutive frames using the Farneback method (cvCalcOpticalFlowFarneback()).
- If the motion detected between the two frames exceeds the given threshold value, the current frame is saved as an image file.
- The program also has a delay of 10secs which can be configured or removed as needed.