text: 
  // Compile with g++ -o test test.cpp `pkg-config opencv4 --cflags --libs`
  // Test with ./test
  #include <iostream>
  #include <opencv2/opencv.hpp>
  #include <unistd.h>
  #include <fstream>
  #include <iterator>
  //Defines
  #define minArea 500
  //Namespaces
  using namespace cv;
  using namespace std;
  //Constants
  Point points[20][20];
  Mat firstFrame_Blur, lastFrame_Blur, difFrame, thrFrame, dilateFrame;
  Mat firstFrame = imread("first.jpg", IMREAD_GRAYSCALE);
  Mat lastFrame = imread("last.jpg", IMREAD_GRAYSCALE);
  vector<vector<Point>> cnts;
  //Main
  int main(int argc, char * argv[]) {
      int maxPoints = 3;
      // Read X file
      ifstream fileX("vectorX");
      istream_iterator<int> startX(fileX), endX;
      vector<int> numbersX(startX, endX);
      fileX.close();
      // Read Y file
      ifstream fileY("vectorY");
      istream_iterator<int> startY(fileY), endY;
      vector<int> numbersY(startY, endY);
      fileY.close();
      // Fills points array
      int pointId = 0;
      int polygonId = 0;
      for (int i=0; i<numbersX.size(); i++){
          points[polygonId][pointId] = Point(numbersX[i],numbersY[i]);
          //cout << polygon << " " << pointNumber <<" " << points[polygon][pointNumber] << " "<< i <<endl;
          pointId++;
          //if(pointNumber==3){pointNumber=0;}  // New polygon
          if((i+1)%maxPoints==0){ //New polygon, pointId is zero
              pointId=0;
              polygonId++;
          }
      }
  
      for(int i = 0; i<maxPoints; i++){
          const Point* ppt[1] = {points[i]};
          int npt[] = {maxPoints};
          fillPoly( firstFrame, ppt, npt, 1, Scalar( 250, 255, 255 ), LINE_8);	// frame, array of points, counter, number of contours, color, line type
          fillPoly( lastFrame, ppt, npt, 1, Scalar( 250, 255, 255 ), LINE_8);	// frame, array of points, counter, number of contours, color, line type
      }
      // Image processing
      GaussianBlur(firstFrame, firstFrame_Blur, Size(21, 21), 0);
      GaussianBlur(lastFrame, lastFrame_Blur, Size(21, 21), 0);
      absdiff(firstFrame_Blur, lastFrame_Blur, difFrame);
      threshold(difFrame, thrFrame, 30, 255, THRESH_BINARY);  //try threshold between 10 (more sensible) and 50 (less sensible)
      dilate(thrFrame, dilateFrame, Mat(), Point(-1,-1), 2);
      findContours(dilateFrame, cnts, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
      vector<Rect> boundRect(cnts.size());
      double area, sumArea = 0;
      for(int i = 0; i< cnts.size(); i++){
          area = contourArea(cnts[i]);    //motion areas
          cout << area << endl;
          sumArea += area;    //total motion area (500 is a good area in the tests)
          if(area > minArea ){
              boundRect[i] = boundingRect(cnts[i]);
              rectangle( firstFrame, boundRect[i].tl(), boundRect[i].br(), Scalar(0, 255, 255), 2 );
          }
      }
      // Show image
      imshow( "test", firstFrame);
      waitKey( 0 );
      return 0;
  }
  