www.pudn.com > colortracker.rar > main.cpp


#pragma warning(disable : 4786) 
#include "pp_preprocessor.h" 
#include "colorfeatsearch.h" 
#include  
#include "mainutil.h" 
#include  
#include  
#include  
 
using namespace std; 
 
/* ================================================================ */ 
 
int main() { 
 
	system("rmdir temp"); 
	_mkdir("temp"); 
 
	int imageWidth = 25; 
	int imageHeight = 25; 
	double scaleUpPct = 0;//0.1;//0.1;// 0;//0.1; 
	double shiftPct = .1;//0.05;//0.05;// 0;//0.5; 
	double minSizePct = .1;//0.1; 
	int minScaleUp = 1;//3; 
	int minStride = 1;//1;//3;	 
 
	int scaledev = 1; /* window over valid scales is cur +/- scaledev */ 
	double hr = .75; /* window over location is in units of current face scale */ 
		 
	TIntegral likratimage, backimage; 
	likratimage.setSize(imageWidth, imageHeight); 
	backimage.setSize(imageWidth, imageHeight); 
 
// 	drawBack(backimage, 0, 0); 
// 	drawBack(backimage, -9.3777f, 1.1774f); 
 
	TBox besthyp; 
	 
	MPColorFeatSearch *colorFeatSearchptr = new MPColorFeatSearch; 
	MPColorFeatSearch &colorFeatSearch = *colorFeatSearchptr; 
 
	colorFeatSearch.initPyramids(imageWidth, imageHeight, scaleUpPct, minSizePct, minScaleUp, shiftPct, minStride); 
	 
	TBox roi; 
	list ROIs; 
 
	Timeline timeline; 
	 
#ifdef SPIKETEST 
	timeline.addEntry(0, 0, 0, 0, 0, 0, 0, 20); 
#else 
	timeline.addEntry(0, 4, 20, 4, 4, 5, 5, 20); 
	timeline.addEntry(0, 20, 4, 18, 18, 5, 5, 20);	 
	timeline.addEntry(21, -1, -1, -1, -1, 0, 0, 10); 
#endif 
// 	FILE *fid2 = fopen("temp/results.txt", "w"); fclose(fid2); 
 
	for (int trial = 0; trial < timeline.numframes; trial++) { 
		drawBack(likratimage, -6.f, 0.f);		 
 
		timeline.getROISequences(trial, ROIs); 
 
		for (list::iterator it = ROIs.begin(); it != ROIs.end(); it++) { 
			ROISequence *s = *it; 
			s->getnext(roi.x, roi.y, roi.size); 
  			drawROI(likratimage, roi, 10.f, 0.f); 
		} 
 
		TIntegral likimg; 
		likimg.setSize(likratimage.getImWidth(), likratimage.getImHeight()); 
		for (int y = 0; y < likratimage.getIntHeight(); y++) { 
			for (int x = 0; x < likratimage.getIntWidth(); x++) { 
				likimg.setIntPixel(x, y, likratimage.getIntPixel(x, y)); 
			} 
		} 
 
		likratimage.integrate(); 
 
		besthyp.x = 0; besthyp.y = 0; besthyp.size = 1; besthyp.scale = 1; 
		 
		double start_time = (double)clock()/CLOCKS_PER_SEC; 
		double likrat = colorFeatSearch.searchFeature(likratimage, NULL, besthyp, scaledev, hr, shiftPct, scaleUpPct, minSizePct, minScaleUp, minStride); 
		double elapsed = (double)clock()/CLOCKS_PER_SEC - start_time; 
 
		for (y = besthyp.y; y < besthyp.y+besthyp.size; y++) { 
			for (int x = besthyp.x; x < besthyp.x+besthyp.size; x++) { 
				if (x == besthyp.x || x == besthyp.x + besthyp.size-1) 
					likimg.setImPixel(x, y, 0); 
				else if (y == besthyp.y || y == besthyp.y + besthyp.size-1) 
					likimg.setImPixel(x, y, 0); 
			} 
		} 
 
		char filename[100]; 
		sprintf(filename, "temp/image_%d.bin", trial); 
		likimg.printImBin(filename, true); 
 
//  		FILE *fid2 = fopen("temp/results.txt", "a"); 
//  		fprintf(fid2, "%f\t%f\t%f\n", besthyp.x, besthyp.y, besthyp.size); 
//  		fclose(fid2); 
 
		printf("trial %d\telapsed time %g\n",trial, elapsed); 
	} 
 
	return (0); 
} 
 
/* ================================================================ */