#include <iostream>
#include <opencv2/opencv.hpp>

#include "dataunit.hpp"
#include "changedetection.hpp"
#include "preprocess.hpp"
#include "register.hpp"
#include "normalize.hpp"
#include "detectdiff.hpp"
#include "detectratio.hpp"
#include "detectshading.hpp"
#include "detectcorr.hpp"
#include "detectdiffcorr.hpp"
#include "evaluate.hpp"
#include "detectlbp.hpp"

using namespace std;
using namespace cv;

int main(int argc, char **argv) {
  DataUnit data;
  
  if( argc < 6 ){
    cerr << "compare <template> <template_roi>"
         << " <input_image> <ground_truth> <output_mask>\n";
    return 1;
  }
  
  // Load images
  data.mMat[TEMP] = imread(argv[1], IMREAD_GRAYSCALE);
  if( data.mMat[TEMP].empty() ){
    cerr << "Unable to load template image '"<< argv[1] << "'.\n";
    return 1;
  }
  
  data.mMat[TROI] = imread(argv[2], IMREAD_GRAYSCALE);
  if( data.mMat[TROI].empty() ){
    cerr << "Unable to load template region of interest image '" << argv[2]
         << "'.";
    return 1;
  }
  
  data.mMat[INPU] = imread(argv[3], IMREAD_COLOR);
  if( data.mMat[INPU].empty() ){
    cerr << "Unable to load input image '" << argv[3] << "'.\n";
    return 1;
  }
  
  data.mMat[GTRU] = imread(argv[4], IMREAD_GRAYSCALE);
  if( data.mMat[GTRU].empty() ){
    cerr << "Unable to load ground truth mask '" << argv[4] <<"'.\n";
    return 1;
  }
 

  ChangeDetection detection;
  detection.setData(data);
 
  DetectLBP detLBP;
  detection.addPipe(&detLBP);
  
  // Start the pipeline
  DataUnit out = detection.detect();

  imshow("Out", out.mMat[OUTP]);
  waitKey();
  //imwrite(argv[5], out.mMat[OUTP]);
  return 0;
}
