Create a motion detector
We have already set up a piece of software called motion. It detects and captures motion, but that's not fun at all compared to building our own code to capture motion. We will create code that will detect motion and take a decision according to the extent of motion. We will trigger an LED to indicate the decision taken by the RasPi. This code is going to be a bit long, so the explanation is given in comments within the code. However, important information is provided just after the end of the code:
#include <iostream> #include <cv.h> #include <highgui.h> #include <stdio.h> #include <cctype> #include <iterator> #include <unistd.h> #include <wiringPi.h> #include "opencv2/highgui/highgui.hpp" #include <time.h> using namespace cv; using namespace std; int main() { /*----Section 1 -----------------Declarations------------------*/ wiringPiSetup(); //To toggle LED, Essential pinMode(0, OUTPUT); //BCM_GPIO pin 17 CvMemStorage...