/*
* This file is part of robotreality
*
* Copyright(c) sschulz <AT> techfak.uni-bielefeld.de
* http://opensource.cit-ec.de/projects/robotreality
*
* This file may be licensed under the terms of the
* GNU General Public License Version 3 (the ``GPL''),
* or (at your option) any later version.
*
* Software distributed under the License is distributed
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the GPL for the specific language
* governing rights and limitations.
*
* You should have received a copy of the GPL along with this
* program. If not, go to http://www.gnu.org/licenses/gpl.html
* or write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* The development of this software was supported by the
* Excellence Cluster EXC 277 Cognitive Interaction Technology.
* The Excellence Cluster EXC 277 is a grant of the Deutsche
* Forschungsgemeinschaft (DFG) in the context of the German
* Excellence Initiative.
*
*/

#include "DotTracker.h"
#include "XIMU.h"


int main(int argc, char** argv){
	
	printf("\n");
	printf(",---------------------------------------------.\n");
	printf("| robotreality live mocap tracking            |\n");
	printf("`---------------------------------------------´\n\n");
	printf("NOTE: intended to be used with an Firewire ptGrey FireflyMV!\n\n");
	
	if (argc == 2){
		if ((strcmp(argv[1],"-help")==0) || (strcmp(argv[1],"--help")==0)){
			printf("> usage: \n");
			printf("          %s                     (default settings)\n", argv[0]);
			printf("          %s <config filename>   (loads given config)\n\n", argv[0]);
			exit(1);
		}
	}

	DotTracker *tracker;
	if (argc == 2){
		tracker = new DotTracker(argv[1]);
	}else{
		tracker = new DotTracker(NULL);
	}
	
	printf("> setting mouse handler\n");
	tracker->init_mousehandler();
	
	printf("> starting tracking\n");
	tracker->do_tracking();
	
	
	return 0;
}


#if 0
#include <cv.h>
#include <highgui.h>

using namespace cv;

int main(){
CvCapture* capture = NULL;
IplImage *frame = NULL;
IplImage *result = NULL;
IplImage *bayer = NULL; 

CvFont font;
double hScale=0.5;
double vScale=0.5;
int lineWidth=2;

cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, hScale, vScale, 0, lineWidth);

capture = cvCreateCameraCapture(0);



if (capture) {
	printf("> got capture\n");
	cvNamedWindow("Capture", CV_WINDOW_AUTOSIZE);
	cvSetCaptureProperty(capture, CV_CAP_PROP_FPS, 60.0);
}


while(true){
	frame = cvQueryFrame(capture);
	if( !frame ){
		printf("did not get frame\n");
		break;
	}
printf("FRAME\n");
//	result = cvCloneImage(frame);

	cvSetImageCOI(frame,1);

	bayer = cvCreateImage( cvGetSize(frame), IPL_DEPTH_8U, 1);
	cvCopy(frame,bayer,NULL);

	result=cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 3);
	cvCvtColor(bayer,result,CV_BayerRG2RGB); //CV_BayerGB2RGB); 

//	cvSetImageCOI(frame,1);
//	cvCvtColor(frame,result,CV_BayerGB2RGB); 


	//cvPutText(result, text_fps, cvPoint(0,20), &font, cvScalar(255,255,0));
	cvShowImage("Capture", result);
	if(cvWaitKey(10) != -1){
		printf("keypress\n");
		break;
	}
}

}
#endif