Пример #1
0
void TestDetection()
{
	DetectionModule *pDM = new DetectionModule();

	pDM->Init("E:\\ImDetection\\ImDetectionApp\\Test\\Rscreen_shortFinger.avi");

	pDM->DoDetection();

	SimpleFingerDetectionResultSet resultSet;

	pDM->GetDetectionResult(resultSet);

	for(int x=0; x<resultSet.m_nFrameNum; x++)
	{
		SimpleDetectionResult* &currDR = resultSet.m_arrSimpleDR[x];
		WCHAR str[MAX_PATH];
		swprintf(str, L"[shooting] %d , fingerNum = %d \n",x,currDR->GetFingerNum());
		//cout << str <<endl;
		OutputDebugStringW(str);
		//_DPRINTF((L"%d , fingerNum = %d \n",x,m_pDetectionModule->m_arrDetectionResults[x]->m_nFingerNum));
	}

	ParameterSet paramSet;
	pDM->GetParameters(paramSet);

	for(int x=0; x<paramSet.GetParamNum(); x++)
	{
		cout << "x = " <<x <<"name = " << paramSet.GetParameterName(x) << "value = " << paramSet.GetParameterByIndex(x) <<endl;
		//printf("%d, %s %d \n",x,paramSet.GetParameterName(x),paramSet.GetParameter(x));
	}

	paramSet.SetParameterByIndex(4,60/255.0);

	pDM->DoDetection();

	delete pDM;

}
Пример #2
0
void TestClasses()
{
	ParamSetAndMeasurement pam;
	pam = LoaderAndWriter::LoadParameterSetAndMeasurementFromFile("E:\\ImDetection\\ImDetectionApp\\OptimalParameterEstimation\\Result5\\TotalResult.txt");

	for(int x=36; x >=30; x--)
	{
		vector<int> vecIndex = pam.GetParamSetAndMeasurementSetPairIndexArrByScore(x);
		char filaname[MAX_PATH];
		sprintf(filaname,"E:\\ImDetection\\ImDetectionApp\\OptimalParameterEstimation\\Result5\\%d.txt",x);
		LoaderAndWriter::WriteSpecificParameterSetAndMeasurementToFile(pam,vecIndex,filaname);
	}
	CalculateScore cal;
	LoaderAndWriter myLoaderAndWriter;

	{



		SimpleFingerDetectionResultSet fileResultSet = myLoaderAndWriter.LoadDetectionResultSetFromFile("GT.txt");
		SimpleFingerDetectionResultSet resultSetDR = myLoaderAndWriter.LoadDetectionResultSetFromFile("DR.txt");

		cal.SetGroundTruth(fileResultSet);
		cal.SetDetectionResult(resultSetDR);
	}

	MeasurementSet ms;
	cal.DoCalculateScore(&ms);

	SimpleFingerDetectionResultSet resultSetDR;
	cal.GetDetectionResult(&resultSetDR);
	myLoaderAndWriter.WriteDetectionResultSetToFile(resultSetDR,"test_write.txt");


	ParamSetAndMeasurementSet pair;
	{
		ParameterSet paramSet;
		paramSet.AddParameter("ABC",10);
		paramSet.AddParameter("DEf",10);
		pair.AddParamSetAndMeasurementSetPair(paramSet,ms);
	}
	LoaderAndWriter::WriteParameterSetAndMeasurementSetToFile(pair,"paraAndmeasure.txt");

	ParameterSet paramSet2;
	//pair.GetParamSetAndScorePair(0,&paramSet2,&score2);

	paramSet2;

	NextParametersGenerator myGenerator;


	ParameterSet paramSet3;
	paramSet3.AddParameter("A",0.2);
	paramSet3.AddParameter("B",10);
	paramSet3.AddParameter("C",1);


	ParameterSetRange paramSetRange;
	paramSetRange.AddParameterRange(0,1,0.2);
	paramSetRange.AddParameterRange(5,15,5);
	paramSetRange.AddParameterRange(1,7,2);

	double low,high,step;
	paramSetRange.GetParameterRange(0,&low,&high,&step);

	ParameterSet iteParamSet;
	bool flagFinish = false;
	myGenerator.Init(paramSet3,paramSetRange);

	int counter = 0;
	while(!flagFinish)
	{
		myGenerator.GetNextParamSet(&iteParamSet);

		for(int x=0; x<iteParamSet.GetParamNum(); x++)
		{
			cout << iteParamSet.GetParameterName(x) << "," << iteParamSet.GetParameterByIndex(x) <<endl;
		}

		cout << "=================== "<< counter <<endl;

		myGenerator.GenerateNextParamSet(&flagFinish);

		counter++;
	}


	system("pause");
}
Пример #3
0
void TestAllParamAndMeasurementByTraceSet()
{
	char folderName[MAX_PATH] = "640x480_RandomLine";
	//IplImage *img = cvLoadImage("GT_Line_thin.png",0);
	IplImage *img = cvLoadImage("640x480_RandomLine/RandomLine_flip_fgIsWhite.png",0);
	ParamSetAndMeasurementByTraceSet m_paraSetAndMeasurementByTraceSet;

	//=== Init CalculateScore ===
	CalculateScore_Dynamic myCal;
	myCal.Init(img,15,720/2);

	//=== Init parameter generator
	ParameterSet paraSet;
	paraSet.AddParameter("SubBgValue",0);
	paraSet.AddParameter("SimpleHighPassWindowHalf",8);
	paraSet.AddParameter("Threshold",25);
	paraSet.AddParameter("FingerSize",60);

	ParameterSetRange paramSetRange;
	paramSetRange.AddParameterRange(0, 20, 5); // SubBgValue
	paramSetRange.AddParameterRange(8, 12, 1); // SimpleHighPassWindowHalf
	paramSetRange.AddParameterRange(25, 50, 5); // Threshold		
	paramSetRange.AddParameterRange(60, 160, 20); // FingerSize


	NextParametersGenerator m_paraGenerator;
	HRESULT hr = m_paraGenerator.Init(paraSet,paramSetRange);

	


	bool flagFinish = false;
	int counter=0;
	while(!flagFinish)
	{
		m_paraGenerator.GetNextParamSet(&paraSet);
		m_paraGenerator.GenerateNextParamSet(&flagFinish);

		//--- load DR result ---
		char loadFileName[MAX_PATH];
		sprintf(loadFileName,"%s/DR_%.2f_%.2f_%.2f_%.2f.txt",folderName,paraSet.GetParameterByIndex(0),paraSet.GetParameterByIndex(1),paraSet.GetParameterByIndex(2),paraSet.GetParameterByIndex(3));
		SimpleFingerDetectionResultSet DRset = LoaderAndWriter::LoadDetectionResultSetFromFile(loadFileName);
		
		myCal.SetDetectionResult(DRset);

		MeasurementByTraceSet msByTraceSet;
		myCal.DoCalculateScore(&msByTraceSet);

		char saveFileName[MAX_PATH];
		sprintf(saveFileName,"%s/Simple_%.2f_%.2f_%.2f_%.2f.txt",folderName,paraSet.GetParameterByIndex(0),paraSet.GetParameterByIndex(1),paraSet.GetParameterByIndex(2),paraSet.GetParameterByIndex(3));
		//LoaderAndWriter::WriteMeasurementByTraceSetToFile(msByTraceSet,saveFileName);
		LoaderAndWriter::WriteMeasurementByTraceSetToFile_simple(msByTraceSet,saveFileName);

		m_paraSetAndMeasurementByTraceSet.AddParamSetAndMeasurementSetPair(paraSet,msByTraceSet);
	
		//=== Show progress ===
		/*WCHAR str[MAX_PATH];
		float progress;
		int totalIteration, currIteration;
		m_paraGenerator.GetProgress(&progress,&currIteration,&totalIteration);
		printf("Progress %.3f",progress);*/
		printf("%d___%.2f_%.2f_%.2f_%.2f\n",counter,paraSet.GetParameterByIndex(0),paraSet.GetParameterByIndex(1),paraSet.GetParameterByIndex(2),paraSet.GetParameterByIndex(3));
		counter++;
	}

	
	char filename3[MAX_PATH];
	sprintf(filename3,"%s/TotalResult.txt",folderName);
	//LoaderAndWriter::WriteParameterSetAndMeasurementByTraceSetToFile(m_paraSetAndMeasurementByTraceSet,filename3);
	LoaderAndWriter::WriteParameterSetAndMeasurementByTraceSetToFile_simple(m_paraSetAndMeasurementByTraceSet,filename3);
	printf("Finish optimal parameter search!");
	
}