face recognition

face recognition

Hello!

I am sorry to trouble you but I really need some help. Thank you very much!!

Now I want to write a program of face recognition, and I can register the face into the database. However, I need to register the same face a lot of times before my program can recognition this face. My main program is below:

while(sm->AcquireFrame(true) >= sts)
    {
        //update the output data to the latest availible
        faceData->Update();

        //get number of detected faces
        pxcI32 numOfFaces = faceData->QueryNumberOfDetectedFaces();

        //loop through all detected faces
        for(pxcI32 i = 0; i<numOfFaces; i++)
        {
            //retrieve the recognition data instance
            PXCFaceData::Face *face = faceData->QueryFaceByIndex(0);
            PXCFaceData::RecognitionData *rdata = face->QueryRecognition();       

            //recognition the current face
            pxcI32 uid = rdata->QueryUserID();
            //std::cout<<uid<<std::endl;
            //pxcBool flag = rdata->IsRegistered();
            char IfReg;
            if( uid != -1)
            {
                std::cout<<"You have registered already."<<std::endl;
                std::cout<<"User's ID is:"<<uid<<std::endl;

                char iFlag;
                std::cout<<"Do you want to go on? (Y for Yes and N for No to exit.)"<<std::endl;
                std::cin>>iFlag;
                if(iFlag == 'Y')
                    break;
                else
                {
                    //pxcBYTE *buffer = malloc(rcgMData->QueryDatabseSize());
                    pxcI32 nbytes = rcgMData->QueryDatabaseSize();
                    pxcBYTE *buffer = new pxcBYTE[nbytes];    
                    rcgMData->QueryDatabaseBuffer(buffer);

                    fwrite(buffer, nbytes, 1, filepath);
                    fclose(filepath);

                    delete [] buffer;

                    cfg->Release();
                    sm->Release();

                    return 0;

                }
            }
            else   
            {
                pxcI32 rid = rdata->RegisterUser();
                std::cout<<"Registered successfully. Your Id is:"<<rid<<std::endl;
                break;
            }

        }

        sm->ReleaseFrame();
    }

 

What's more, how can I reload the database saved in my computer next time?

 

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hi Zhang S.

Please take a look at UseStorage or SetDatabaseBuffer methods of PXCFaceConfiguration::RecognitionConfiguration interface.

Best regards,

Artem

Quote:

Artem Vorobiev (Intel) wrote:

Hi Zhang S.

Please take a look at UseStorage or SetDatabaseBuffer methods of PXCFaceConfiguration::RecognitionConfiguration interface.

Best regards,

Artem

Dear Artem:

Thank you for your answer. But I still have a question. If there any problems in my program above? When I run the program, it should register my face for several times. It means that the same face has many user IDs(from 100 to 214 for example), at last, it can recognition my face and give my user ID 131 but not 100. My program is shown below. Could you please tell me the reason of this please? Or could you send me a single sample of face recognition?

Best regards,

Siven

//face recignition and load the database to the disk

# include <iostream>
# include <util_render.h>
# include <pxcsensemanager.h>
# include <pxcfacemodule.h>
# include <pxcfaceconfiguration.h>
# include <pxcfacedata.h>
# include <pxcimage.h>
# include <stdio.h>
# include <string>

int main()
{
	pxcStatus sts = PXC_STATUS_NO_ERROR;

	//create the PXCSenseManager
	PXCSenseManager *sm = NULL;
	sm = PXCSenseManager::CreateInstance();
	if(!sm)
	{
		wprintf(L"Unable to create the PXCSenseManager.\n");
		return 1;
	}

	//enable the face tracking 
	if(sm->EnableFace() < sts)
	{
		wprintf_s(L"Unable to enable the face analysis.\n");
		return 2;
	}

	//initialize the pipeline
	sm->Init();

	//retrieve face module if ready
	PXCFaceModule *faceAnalyzer = sm->QueryFace();

	//retrieves an instance of the PXCFaceConfiguration interface
	PXCFaceConfiguration *cfg = faceAnalyzer->CreateActiveConfiguration();
	cfg->EnableAllAlerts();
	//cfg->ApplyChanges();

	// configure face recognition
	PXCFaceConfiguration::RecognitionConfiguration *rcfg = cfg->QueryRecognition();
	//enable face recognition
	rcfg->Enable();
	rcfg->properties.isEnabled = true;

	//retrieves an instance of the PXCFaceData interface
	PXCFaceData *faceData = faceAnalyzer->CreateOutput();

	PXCFaceData::RecognitionModuleData *rcgMData = faceData->QueryRecognitionModule();

	//create a recognition database
	PXCFaceConfiguration::RecognitionConfiguration::RecognitionStorageDesc desc = {};
	desc.maxUsers = 10;		

	rcfg->CreateStorage(L"MyFacesDatabase", &desc);
	rcfg->UseStorage(L"MyFacesDatabase");


	//make it effective
	cfg->ApplyChanges();

	FILE *filepath = fopen("facedatabse.txt", "wt+");

	//stream data
	PXCImage *image = NULL;
	while(sm->AcquireFrame(true) >= sts)
	{
		//update the output data to the latest availible
		faceData->Update();

		//get number of detected faces
		pxcI32 numOfFaces = faceData->QueryNumberOfDetectedFaces();

		//loop through all detected faces
		for(pxcI32 i = 0; i<numOfFaces; i++)
		{
			//retrieve the recognition data instance
			PXCFaceData::Face *face = faceData->QueryFaceByIndex(0);
			PXCFaceData::RecognitionData *rdata = face->QueryRecognition();		

			//recognition the current face
			pxcI32 uid = rdata->QueryUserID();
			char IfReg;
			if( uid != -1)
			{
				std::cout<<"You have registered already."<<std::endl;
				std::cout<<"User's ID is:"<<uid<<std::endl;

				char iFlag;
				std::cout<<"Do you want to go on? (Y for Yes and N for No to exit.)"<<std::endl;
				std::cin>>iFlag;
				if(iFlag == 'Y')
					break;
				else
				{
					pxcI32 nbytes = rcgMData->QueryDatabaseSize();
					pxcBYTE *buffer = new pxcBYTE[nbytes];	
					rcgMData->QueryDatabaseBuffer(buffer);
					fwrite(buffer, nbytes, 1, filepath);
	
					fclose(filepath);
	
					delete [] buffer;

					cfg->Release();
					sm->Release();

					return 0;

				}
			}
			else	
			{
				pxcI32 rid = rdata->RegisterUser();
				std::cout<<"Registered successfully. Your Id is:"<<rid<<std::endl;
				break;
			}

		}

		sm->ReleaseFrame();
	}


	return 0;
}

 

Any idea why QueryNumberOfDetectedFaces(); returns zero for me?

Here's my code snippet:

 senseManager.EnableFace();
                PXCMFaceModule faceModule = senseManager.QueryFace();
                PXCMFaceConfiguration faceConfig = faceModule.CreateActiveConfiguration();
                faceConfig.detection.isEnabled = true;
                faceConfig.detection.maxTrackedFaces = 2;
                faceConfig.landmarks.isEnabled = true;
                faceConfig.ApplyChanges();
                faceConfig.Dispose();
                
               
                PXCMFaceData faceData = faceModule.CreateOutput();
                faceData.Update();
                int numFaces = faceData.QueryNumberOfDetectedFaces();
                Console.WriteLine(numFaces);
                //PXCMFaceData.Face face = faceData.QueryFaceByIndex(0);

                //for (int i = 0; i < numFaces; i++)  {
                  Console.WriteLine("We got here!");
				  PXCMFaceData.Face f = faceData.QueryFaceByIndex(0);
                  Console.WriteLine("We got here too!");
				  PXCMFaceData.PoseData p = f.QueryPose();
				  PXCMPoint3DF32 outHeadPosition = new PXCMPoint3DF32();
               

 

Leave a Comment

Please sign in to add a comment. Not a member? Join today