#include <opencv/cv.h>
extern "C"
{
#include <opencv/highgui.h>
}
#include <cmath>
#include <iostream>
#include "../libseemicro/seemicro.h"

using namespace std;
using namespace seemicro;

IplImage *img;

int main(int argc, char** argv)
{
	if(argc != 2 && argc != 3)
	{
		cerr << "Call me as: " << argv[0] << " <inputimage> [<outputimage>]\n";
		return 1;
	}
	ImageFile i(argv[1]);

	MicroAdam dummy;
	CorrelationModule corr(dummy, i, &dummy);
	HSVRange range;
	range.smin = 55;

	FindLEDSModule f(i, dummy, corr, range);

        cout << "HSVRange: " << range << endl;

	//f.processKeyFrame();
	//short unsigned int markiert;
	myrect ROI = myrect(0, 0, i.img->width, i.img->height);
	f.FloodFill(f.img, ROI, f.markiert, range);

        cout << "Vergebene Markierungen: " << f. markiert << endl;

     	IplImage* out = cvCreateImage(cvSize(i.img->width, i.img->height), IPL_DEPTH_8U, 3);
	f.FloodFillMarks2Colors(out);

	for(int j=0; j<f.markiert; j++)
	{
	  cout << "marke #" << j+1 << " schwerpunkt=(" << f.markierungen[j].p.x << "," << f.markierungen[j].p.y << ") pixel="
	    << f.anzahl[j] << endl;
	}

	if(argc==2)
	{
	  cvNamedWindow("FloodFill", 1);
	  cvShowImage("FloodFill", out);
          cvWaitKey();
	}
	else cvSaveImage(argv[2], out);

	cvReleaseImage(&img);
	cvReleaseImage(&out);
	cvDestroyWindow("FloodFill");
	return 0;
}

