void TestNewMethod() { HRESULT hr; //IplImage* img = cvLoadImage("TestLine.png",0); IplImage *img = cvLoadImage("imgCenterLine_draw.png",0); SimpleFingerDetectionResultSet DRset = LoaderAndWriter::LoadDetectionResultSetFromFile("DR_17.16_10.42_13.42_93.41.txt"); // multi-result CalculateScore_Dynamic myCal; //myCal.Init(img,5); myCal.Init(img,10,1000); myCal.SetDetectionResult(DRset); MeasurementByTraceSet* msByTraceSet = new MeasurementByTraceSet(); myCal.DoCalculateScore(msByTraceSet); LoaderAndWriter::WriteMeasurementByTraceSetToFile_new(*msByTraceSet,"newMeasurementByTraceSet.txt"); ParameterSet paramSet; paramSet.AddParameter("A",0); paramSet.AddParameter("B",1); paramSet.AddParameter("C",2); ParamSetAndMeasurementByTraceSet tmp; tmp.AddParamSetAndMeasurementSetAndWeightPair(paramSet,*msByTraceSet,0.5); LoaderAndWriter::WriteParameterSetAndMeasurementByTraceSetToFile_new(tmp,"newParaAndMeasurementByTraceSet.txt",1); int x=0; }
void TestCalculateScore_Dynamic_Rules() { HRESULT hr; IplImage* img = cvLoadImage("TestLine.png",0); SimpleFingerDetectionResultSet DRset = LoaderAndWriter::LoadDetectionResultSetFromFile("DR_20.00_12.00_50.00_160.00.txt"); MeasurementByRulesSet* measurementSet = new MeasurementByRulesSet(); CalculateScore_Dynamic myCal; myCal.Init(img,20); myCal.SetDetectionResult(DRset); //myCal.DoCalculateScore(measurementSet); //hr = myCal.RuleGetDiffAmongDRandGT_Set(1,DRset,*measurementSet); //hr = myCal.RuleGetDistToTrace_Set(DRset,*measurementSet); //hr = myCal.RuleCheckContinuous_Set(181,264,2,DRset,*measurementSet); LoaderAndWriter::WriteMeasurementByRulesSetToFile(*measurementSet,"MeasurementByRulesSet.txt"); measurementSet->SetStartAndEndFrameNo(181,264); float rate = measurementSet->GetGoodFrameRate(); ParameterSet paramSet; paramSet.AddParameter("A",0); paramSet.AddParameter("B",1); paramSet.AddParameter("C",2); ParamSetAndMeasurementByRulesSet tmp; tmp.AddParamSetAndMeasurementSetPair(paramSet,*measurementSet); LoaderAndWriter::WriteParameterSetAndMeasurementByRulesSetToFile(tmp,"ParamSetAndMeasurementByRulesSet.txt"); }
ParameterSet DetectionModule_touchLib::GetDefaultParameters() { ParameterSet paramSet; paramSet.AddParameter("SubBgValue",m_pISubBgFilter->GetSubtractValue()); paramSet.AddParameter("SimpleHighPassWindowHalf",m_pISimpleHighPassFilter->GetSmoothMaskWidthHalf()); //let window width and height size be equal paramSet.AddParameter("Scale",m_pIScaleFilter->GetScale()); paramSet.AddParameter("Threshold",m_pIThresholdFilter->GetThreshold()*255.0); paramSet.AddParameter("FingerSize",m_pIFindBlobFilter->GetThreshFingerSize()); /* paramSet.m_paramsName.push_back("SubBgValue"); paramSet.m_paramsName.push_back("SimpleHighPassWidthHalf"); paramSet.m_paramsName.push_back("SimpleHighPassHeightHalf"); paramSet.m_paramsName.push_back("Scale"); paramSet.m_paramsName.push_back("Threshold"); paramSet.m_paramsName.push_back("FingerSize"); paramSet.m_params.push_back(m_pISubBgFilter->GetSubtractValue()); paramSet.m_params.push_back(m_pISimpleHighPassFilter->GetSmoothMaskWidthHalf()); paramSet.m_params.push_back(m_pISimpleHighPassFilter->GetSmoothMaskHeightHalf()); paramSet.m_params.push_back(m_pIScaleFilter->GetScale()); paramSet.m_params.push_back(m_pIThresholdFilter->GetThreshold()); paramSet.m_params.push_back(m_pIFindBlobFilter->GetThreshFingerSize()); */ /*paramSet.Init(6); paramSet.SetParameterName(0,"SubBgValue"); paramSet.SetParameterName(1,"SimpleHighPassWidthHalf"); paramSet.SetParameterName(2,"SimpleHighPassHeightHalf"); paramSet.SetParameterName(3,"Scale"); paramSet.SetParameterName(4,"Threshold"); paramSet.SetParameterName(5,"FingerSize"); if(m_pISubBgFilter!=NULL) paramSet.SetParameter(0,m_pISubBgFilter->GetSubtractValue()); if(m_pISimpleHighPassFilter!=NULL) paramSet.SetParameter(1,m_pISimpleHighPassFilter->GetSmoothMaskWidthHalf()); if(m_pISimpleHighPassFilter!=NULL) paramSet.SetParameter(2,m_pISimpleHighPassFilter->GetSmoothMaskHeightHalf()); if(m_pIScaleFilter!=NULL) paramSet.SetParameter(3,m_pIScaleFilter->GetScale()); if(m_pIThresholdFilter!=NULL) paramSet.SetParameter(4,m_pIThresholdFilter->GetThreshold()); if(m_pIFindBlobFilter!=NULL) paramSet.SetParameter(5,m_pIFindBlobFilter->GetThreshFingerSize());*/ return paramSet; }
void TestWriteParameterSetAndMeasurementByTraceSetToFile() { HRESULT hr; //IplImage* img = cvLoadImage("TestLine.png",0); IplImage *img = cvLoadImage("GT_Line_thin.png",0); SimpleFingerDetectionResultSet DRset = LoaderAndWriter::LoadDetectionResultSetFromFile("DR_0.00_8.00_30.00_140.00.txt"); // multi-result //SimpleFingerDetectionResultSet DRset = LoaderAndWriter::LoadDetectionResultSetFromFile("DR_0.00_8.00_40.00_160.00.txt"); // one result //SimpleFingerDetectionResultSet DRset = LoaderAndWriter::LoadDetectionResultSetFromFile("DR_20.00_12.00_50.00_160.00.txt"); // no result MeasurementByTraceSet* msByTraceSet = new MeasurementByTraceSet(); MeasurementByTrace ms; DataSequence seq; ParameterSet paramSet; paramSet.AddParameter("A",0); paramSet.AddParameter("B",1); paramSet.AddParameter("C",2); CalculateScore_Dynamic myCal; //myCal.Init(img,5); myCal.Init(img,15,720/2); myCal.SetDetectionResult(DRset); DataSequenceSet dataSeqSet; //myCal.GetSequenceStartAndEnd(dataSeqSet); //myCal.GetSequenceStartAndEnd(seq); //myCal.CalculateScoreOneFrame(64,DRset.GetSimpleDR_Ptr(64),seq); //myCal.CalculateScoreOneFrame(65,DRset.GetSimpleDR_Ptr(65),seq); //ms = myCal.CalculateScoreOneFrame(72,DRset.GetSimpleDR_Ptr(72),seq); //ms = myCal.CalculateScoreOneFrame(73,DRset.GetSimpleDR_Ptr(73),seq); myCal.DoCalculateScore(msByTraceSet); LoaderAndWriter::WriteMeasurementByTraceSetToFile(*msByTraceSet,"measurementByTrace_new.txt"); ParamSetAndMeasurementByTraceSet tmp; tmp.AddParamSetAndMeasurementSetPair(paramSet,*msByTraceSet); LoaderAndWriter::WriteParameterSetAndMeasurementByTraceSetToFile(tmp,"ParaAndmeasurementByTrace_new.txt"); int x=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,¶mSet2,&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"); }
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(¶Set); 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!"); }