コード例 #1
0
ファイル: faceComparison.cpp プロジェクト: Sayaten/FaceLinker
void compareAllSample()
{
	HImage imgOrg, imgCmp;
	TFacePosition fpOrg, fpCmp;
	FSDK_FaceTemplate ftOrg, ftCmp;

	int result1, result2;
	float similarity = 0.0f, maxSim = 0.0f;
	char *pair1 = NULL, *pair2 = NULL;

	int nFile;
	char **pics;

	std::ofstream fileOut;
	fileOut.open("BadPicsPair.txt");

	pics = getAllFiles(nFile);

	initFaceSDK();

	/* 
		set detection parameters
		first param : set comparing rotation ratio 
					  true == -30 ~ 30 degree, false == -15 ~ 15
		second param : get twisted ratio
					   true == get , false == not get
		third param : set internal resize ratio
	*/
	FSDK_SetFaceDetectionParameters(false, false, 500);

	for(int i = 0 ; i < nFile - 1; ++i)
	{
		for(int j = i + 1 ; j < nFile ; ++j)
		{
			//std::cout<<"=================== This pair ===================="<<std::endl;
			//std::cout<<pics[i]<<" "<<pics[j]<<std::endl<<std::endl;

			// load 2 imgs
			result1 = FSDK_LoadImageFromFile(&imgOrg, pics[i]);
			result2 = FSDK_LoadImageFromFile(&imgCmp, pics[j]);
		
			//std::cout<<"=================== Load Image ==================="<<std::endl;
			//std::cout<<ErrorCode[-result1]<<std::endl;
			//std::cout<<ErrorCode[-result2]<<std::endl<<std::endl;
		
			// find faces
			result1 = FSDK_DetectFace(imgOrg, &fpOrg);
			result2 = FSDK_DetectFace(imgCmp, &fpCmp);
			if(result1 != FSDKE_OK || result2 != FSDKE_OK)
			{
				std::cout<<"============= break this comparation ============="<<std::endl<<std::endl;
				if(result1 != FSDKE_OK) fileOut<<pics[i]<<std::endl;
				if(result2 != FSDKE_OK) fileOut<<pics[j]<<std::endl;

				FSDK_FreeImage(imgOrg);
				FSDK_FreeImage(imgCmp);
				break;
			}
			
			//std::cout<<"=================== Find Faces ==================="<<std::endl;
			//std::cout<<ErrorCode[-result1]<<std::endl;
			//std::cout<<ErrorCode[-result2]<<std::endl<<std::endl;
		
			FSDK_GetFaceTemplateInRegion(imgOrg, &fpOrg, &ftOrg);
			FSDK_GetFaceTemplateInRegion(imgCmp, &fpCmp, &ftCmp);
			
			if(result1 != FSDKE_OK || result2 != FSDKE_OK)
			{
				std::cout<<"============= break this comparation ============="<<std::endl;
				std::cout<<pics[i]<<" "<<pics[j]<<std::endl<<std::endl;
				FSDK_FreeImage(imgOrg);
				FSDK_FreeImage(imgCmp);
				break;
			}

			FSDK_MatchFaces(&ftOrg, &ftCmp, &similarity);
		
			std::cout<<"=================== Similarity ==================="<<std::endl;
			std::cout<<"Similarity is "<<similarity * 100<<"%"<<std::endl<<std::endl;

			if(similarity >= maxSim)
			{
				maxSim = similarity;
				if(pair1 != NULL && pair2 != NULL)
				{
					delete[] pair1;
					delete[] pair2;

					pair1 = NULL;
					pair2 = NULL;
				}
				pair1 = new char[strlen(pics[i]) + 1];
				pair2 = new char[strlen(pics[j]) + 1];

				strcpy(pair1, pics[i]);
				strcpy(pair2, pics[j]);
			}

			FSDK_FreeImage(imgOrg);
			FSDK_FreeImage(imgCmp);
		}
	}

	std::cout<<"===================== Result ====================="<<std::endl;
	std::cout<<"Total "<<nFile<<" files"<< std::endl;
	std::cout<<"Max Similarity: "<<maxSim* 100<<"%"<<std::endl;
	
	std::cout<<pair1<<std::endl;
	std::cout<<pair2<<std::endl;
	

	for(int i = 0 ; i < nFile ; ++i)
		delete[] pics[i];
	delete[] pics;
	delete[] pair1;
	delete[] pair2;

	fileOut.close();

	getchar();
}
コード例 #2
0
ファイル: faceComparison.cpp プロジェクト: Sayaten/FaceLinker
void compareWithOneSample(char* sample)
{
	HImage imgOrg, imgCmp;
	TFacePosition fpOrg, fpCmp;
	FSDK_FaceTemplate ftOrg, ftCmp;

	int result;
	float similarity = 0.0f, maxSim = 0.0f;
	char *pair = NULL;
	char *temp;

	int nFile;
	char **pics;

	std::ofstream fileOut;
	fileOut.open("BadPicsPair.txt");

	pics = getAllFiles(nFile);

	initFaceSDK();

	/* 
		set detection parameters
		first param : set comparing rotation ratio 
					  true == -30 ~ 30 degree, false == -15 ~ 15
		second param : get twisted ratio
					   true == get , false == not get
		third param : set internal resize ratio
	*/
	FSDK_SetFaceDetectionParameters(false, false, 500);

	for(int i = 0 ; i < nFile ; ++i)
	{
		if(!strcmp(pics[i] + strlen("./Pics/"), sample))
		{
			temp = pics[0];
			pics[0] = pics[i];
			pics[i] = temp;
			break;
		}
	}
	
	result = FSDK_LoadImageFromFile(&imgOrg, pics[0]);
	if(result != FSDKE_OK)
	{
		std::cout<<"============= Input Sample is Bad ============"<<std::endl<<std::endl;
		return;
	}
	result = FSDK_DetectFace(imgOrg, &fpOrg);
	if(result != FSDKE_OK)
	{
		std::cout<<"============= Input Sample is Bad ============"<<std::endl<<std::endl;
		return;
	}
	result = FSDK_GetFaceTemplateInRegion(imgOrg, &fpOrg, &ftOrg);
	if(result != FSDKE_OK)
	{
		std::cout<<"============= Input Sample is Bad ============"<<std::endl<<std::endl;
		return;
	}

	for(int i = 1 ; i < nFile ; ++i)
	{
		//std::cout<<"=================== This pair ===================="<<std::endl;
		//std::cout<<pics[i]<<" "<<pics[j]<<std::endl<<std::endl;

		// load 1 imgs
		result = FSDK_LoadImageFromFile(&imgCmp, pics[i]);
	
		//std::cout<<"=================== Load Image ==================="<<std::endl;
		//std::cout<<ErrorCode[-result1]<<std::endl<<std::endl;
	
		// find faces
		result = FSDK_DetectFace(imgCmp, &fpCmp);
		if(result != FSDKE_OK)
		{
			std::cout<<"============= break this comparison ============="<<std::endl<<std::endl;
			if(result != FSDKE_OK) fileOut<<pics[i]<<std::endl;

			FSDK_FreeImage(imgCmp);
			break;
		}
		
		//std::cout<<"=================== Find Faces ==================="<<std::endl;
		//std::cout<<ErrorCode[-result1]<<std::endl<<std::endl;
	
		FSDK_GetFaceTemplateInRegion(imgCmp, &fpCmp, &ftCmp);
		
		if(result != FSDKE_OK)
		{
			std::cout<<"============= break this comparison ============="<<std::endl;
			std::cout<<pics[i]<<std::endl<<std::endl;
			FSDK_FreeImage(imgCmp);
			break;
		}

		FSDK_MatchFaces(&ftOrg, &ftCmp, &similarity);
	
		std::cout<<"=================== Similarity =================="<<std::endl;
		std::cout<<"Similarity is "<<similarity * 100<<"%"<<std::endl<<std::endl;

		if(similarity >= maxSim)
		{
			maxSim = similarity;
			if(pair != NULL)
			{
				delete[] pair;

				pair = NULL;
			}
			pair = new char[strlen(pics[i]) + 1];

			strcpy(pair, pics[i]);
		}
		FSDK_FreeImage(imgCmp);
	}
	
	FSDK_FreeImage(imgOrg);

	std::cout<<"===================== Result ===================="<<std::endl;
	std::cout<<"Total "<<nFile<<" files"<< std::endl;
	std::cout<<"Max Similarity: "<<maxSim* 100<<"%"<<std::endl;
	
	std::cout<<pics[0]<<std::endl;
	std::cout<<pair<<std::endl;
	
	for(int i = 0 ; i < nFile ; ++i)
		delete[] pics[i];
	delete[] pics;
	delete[] pair;

	fileOut.close();

	getchar();
}
コード例 #3
0
ファイル: Unit1.cpp プロジェクト: ScoreSolutions/RFIDHERO2014
void __fastcall TForm1::Button1Click(TObject *Sender)
{
        OpenDialog1->Filter = "JPEG (*.jpg)|*.jpg|Windows bitmap (*.bmp)|*.bmp|All files|*.*";
        if( OpenDialog1->Execute() == True ){
                HImage imageHandle;
                if (FSDK_LoadImageFromFile(&imageHandle, OpenDialog1->FileName.c_str()) != FSDKE_OK)
                        Application->MessageBox("Error loading image", "Error", 0);
                else
                {
                        // resize image to fit the window width
                        int imageWidth;
                        int imageHeight;
                        FSDK_GetImageWidth(imageHandle, &imageWidth);
                        FSDK_GetImageHeight(imageHandle, &imageHeight);
                        double HorRatio = (double)Image1->Width/imageWidth;
                        double VerRatio = (double)Image1->Height/imageHeight;
                        double ratio = (HorRatio < VerRatio) ? HorRatio : VerRatio;
                        HImage image2Handle;
                        FSDK_CreateEmptyImage(&image2Handle);
                        FSDK_ResizeImage(imageHandle, ratio, image2Handle);
                        FSDK_CopyImage(image2Handle, imageHandle);
                        FSDK_FreeImage(image2Handle);

                        HBITMAP hbitmapHandle; // to store the HBITMAP handle
                        // save image into HBITMAP handle
                        FSDK_SaveImageToHBitmap(imageHandle, &hbitmapHandle);

                        Graphics::TBitmap *tpic = new Graphics::TBitmap;
                        tpic->Handle = hbitmapHandle;
                        // display current frame
                        Image1->Picture->Assign(tpic);
                        delete tpic;
                        Application->ProcessMessages();

                        TFacePosition facePosition;
                        if (FSDK_DetectFace(imageHandle, &facePosition) != FSDKE_OK)
                                MessageBox(this->Handle, "No faces detected", "Face Detection", 0);
                        else
                        {
                                int left = facePosition.xc - facePosition.w /2;
                                int top = facePosition.yc - facePosition.w /2;
                                int right = facePosition.xc + facePosition.w /2;
                                int bottom = facePosition.yc + facePosition.w /2;

                                Image1->Canvas->Brush->Style = bsClear;
                                Image1->Canvas->Pen->Color = clLime;
                                Image1->Canvas->Pen->Width = 1;
                                Image1->Canvas->Rectangle(left, top, right, bottom);
                                Application->ProcessMessages();
                                FSDK_Features facialFeatures;
                                FSDK_DetectFacialFeatures(imageHandle, &facialFeatures);

                                for (int i = 2; i < FSDK_FACIAL_FEATURE_COUNT; i++)
                                        Image1->Canvas->Ellipse(facialFeatures[i].x - 2, facialFeatures[i].y - 2,
                                                                facialFeatures[i].x + 2, facialFeatures[i].y + 2);
                                Image1->Canvas->Pen->Color = clBlue;
                                for (int i = 0; i < 2; i++)
                                        Image1->Canvas->Ellipse(facialFeatures[i].x - 2, facialFeatures[i].y - 2, facialFeatures[i].x + 2, facialFeatures[i].y + 2);
                        }
                        FSDK_FreeImage(imageHandle); // delete the FSDK image handle
                }
        }
}