Problem while detecting more than one face Attributes

Problem while detecting more than one face Attributes

Hi,

I am new to PC sdk development,

I am trying to detect face attributes like age,gender and emotion. but it give only one attribute correct for which we set the profile initially.

ex: if I write code like 

attributesEmotion->QueryProfile(PXCFaceAnalysis::Attribute::LABEL_EMOTION,aInfoEmotion);
attributesEmotion->SetProfile(PXCFaceAnalysis::Attribute::LABEL_EMOTION,aInfoEmotion);

attributesGender->QueryProfile(PXCFaceAnalysis::Attribute::LABEL_GENDER,aInfoGender);
attributesGender->SetProfile(PXCFaceAnalysis::Attribute::LABEL_GENDER,aInfoGender);

attributesAge->QueryProfile(PXCFaceAnalysis::Attribute::LABEL_AGE_GROUP,aInfoAge);
attributesAge->SetProfile(PXCFaceAnalysis::Attribute::LABEL_AGE_GROUP,aInfoAge);

then result for emotion will correct but for other two attributes its not giving correct result in QueryData

please suggest if I am missing something here.


Thanks

Yogesh

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

I have forwarded your question to our development team and we will get back to you once I have an answer. Thanks.

Hi,

I am still waiting for result,
Please Let me know if anything wrong in code.
Please find attached image where third attribute's result is wrong, that person is smiling.

Thanks
Yogesh.

Attachments: 

AttachmentSize
Download face-detect.png436.04 KB

I do not know how are you processing the image (i.e. faceAnalyzer->ProcessImageAsync) ?
From the way you are initializing/setting the profiles, I assume you are dynamicly casting each of the PXCFaceAnalysis::Attribute attributesEmotion, attributesGender, and attributesAge separately. Thus you are only processing each of these at a time not all of them. Again this is an assumption since you did not provide me with the code you are developing.

In any case this is how you should do it:

PXCFaceAnalysis::Attribute *attributes=faceAnalyzer->DynamicCast(); // note: PXCFaceAnalysis *faceAnalyzer

attributes->QueryProfile(PXCFaceAnalysis::Attribute::LABEL_EMOTION,aInfoEmotion); //note: attributes not attributesEmotion
attributes->SetProfile(PXCFaceAnalysis::Attribute::LABEL_EMOTION,aInfoEmotion);

attributes->QueryProfile(PXCFaceAnalysis::Attribute::LABEL_GENDER,aInfoGender);
attributes->SetProfile(PXCFaceAnalysis::Attribute::LABEL_GENDER,aInfoGender);

attributes->QueryProfile(PXCFaceAnalysis::Attribute::LABEL_AGE_GROUP,aInfoAge);
attributes->SetProfile(PXCFaceAnalysis::Attribute::LABEL_AGE_GROUP,aInfoAge);

to process the image call: faceAnalyzer->ProcessImageAsync() after capturing the frame
and to get the results call: attributes->QueryData(label,fid,scores) for any of the labels you want (ex: PXCFaceAnalysis::Attribute::LABEL_EMOTION).

Hi Sadaka,

I am proccessing Images as follows

/*******************************************************************************

INTEL CORPORATION PROPRIETARY INFORMATION
This software is supplied under the terms of a license agreement or nondisclosure
agreement with Intel Corporation and may not be copied or disclosed except in
accordance with the terms of that agreement
Copyright(c) 2012 Intel Corporation. All Rights Reserved.

*******************************************************************************/
#include "pxcsmartptr.h"
#include "face_render.h"
#include "util_capture_file.h"
#include "util_cmdline.h"
#include "pxcface.h"
#include "handlerecognizedface.h"
#include "userAttrubutes.h"
#include <iostream>
#include <fstream>
using namespace std;

int wmain(int argc, wchar_t* argv[]) {
// Create a session

if(argc<2)
{
wprintf_s(L"Please enter filename containing configuration parameters ");
return 3;
}
else
{
ifstream myfile (argv[1]);
if(!(myfile && myfile.good()))
{
wprintf_s(L"configuration File does not exist ");
return 3;
}
}
PXCSmartPtr<PXCSession> session;
pxcStatus sts=PXCSession_Create(&session);
if (sts<PXC_STATUS_NO_ERROR) {
wprintf_s(L"Failed to create the SDK session\n");
return 3;
}

HandleRecognizedFace *faceHttpHandler = new HandleRecognizedFace();
UserAttributes *userAttributes = NULL;

UtilCmdLine cmdl(session);
// if (!cmdl.Parse(L"-sdname-nframes-file-record",argc,argv)) return 3;

// Init Face analyzer

PXCSmartPtr<PXCFaceAnalysis> faceAnalyzer;
sts=session->CreateImpl(cmdl.m_iuid, PXCFaceAnalysis::CUID, (void**)&faceAnalyzer);
if (sts<PXC_STATUS_NO_ERROR) {
wprintf_s(L"Failed to locate a face module\n");
return 3;
}

// Retrieve the input requirements
PXCFaceAnalysis::ProfileInfo faInfo;
faceAnalyzer->QueryProfile(0, &faInfo);

// Find capture device
UtilCaptureFile capture(session,cmdl.m_recordedFile,cmdl.m_bRecord);
//Manually set camera
//if(cmdl.m_sdname == NULL)
// cmdl.m_sdname=L"Logitech HD Webcam C270";
if (cmdl.m_sdname) capture.SetFilter(cmdl.m_sdname); /*L"Integrated Camera"*/
sts=capture.LocateStreams(&faInfo.inputs);
if (sts<PXC_STATUS_NO_ERROR) {
wprintf_s(L"Failed to locate an input device for face detection\n");
return 3;
}
faceAnalyzer->SetProfile(&faInfo);

// Create detector instance
PXCFaceAnalysis::Detection *faceDetector=faceAnalyzer->DynamicCast<PXCFaceAnalysis::Detection>();
if (!faceDetector) {
wprintf_s(L"Failed to locate the face detection interface\n");
return 3;
}
//Create Analy instance

// Set detector profile
PXCFaceAnalysis::Detection::ProfileInfo dInfo={0};

faceDetector->QueryProfile(16, &dInfo);
faceDetector->SetProfile(&dInfo);
/*********JOPA******/
PXCFaceAnalysis::Attribute *attributes=faceAnalyzer->DynamicCast<PXCFaceAnalysis::Attribute>();
// PXCFaceAnalysis::Attribute *attributesGender=faceAnalyzer->DynamicCast<PXCFaceAnalysis::Attribute>();
// PXCFaceAnalysis::Attribute *attributesEmotion=faceAnalyzer->DynamicCast<PXCFaceAnalysis::Attribute>();

PXCFaceAnalysis::Attribute::ProfileInfo *aInfoAge=new PXCFaceAnalysis::Attribute::ProfileInfo;
PXCFaceAnalysis::Attribute::ProfileInfo *aInfoGender=new PXCFaceAnalysis::Attribute::ProfileInfo;
PXCFaceAnalysis::Attribute::ProfileInfo *aInfoEmotion=new PXCFaceAnalysis::Attribute::ProfileInfo;

attributes->QueryProfile(PXCFaceAnalysis::Attribute::LABEL_GENDER,aInfoGender);
attributes->SetProfile(PXCFaceAnalysis::Attribute::LABEL_GENDER,aInfoGender);

attributes->QueryProfile(PXCFaceAnalysis::Attribute::LABEL_EMOTION,aInfoEmotion);
attributes->SetProfile(PXCFaceAnalysis::Attribute::LABEL_EMOTION,aInfoEmotion);

attributes->QueryProfile(PXCFaceAnalysis::Attribute::LABEL_AGE_GROUP,aInfoAge);
attributes->SetProfile(PXCFaceAnalysis::Attribute::LABEL_AGE_GROUP,aInfoAge);

// Create Renderer
PXCSmartPtr<FaceRender> faceRender(new FaceRender(L"Face Detection Sample"));
int fnum;
int firstTime = 0;
for (fnum=0;fnum<=cmdl.m_nframes;fnum++) {
PXCSmartArray<PXCImage> images;
PXCSmartSPArray sps(2);

///* read and process frame */
sts = capture.ReadStreamAsync(images,&sps[0]);
if (sts<PXC_STATUS_NO_ERROR) break; // EOF

sts=faceAnalyzer->ProcessImageAsync(images, &sps[1]);
if (sts<PXC_STATUS_NO_ERROR) break;

sts = sps.SynchronizeEx();
if (sps[0]->Synchronize(0)<PXC_STATUS_NO_ERROR) break; // EOF

// loop all faces
faceRender->ClearData();

for (int fidx = 0; ; fidx++)
{
pxcUID fid = 0;
pxcU64 timeStamp = 0;
sts = faceAnalyzer->QueryFace(fidx, &fid, &timeStamp);
if (sts < PXC_STATUS_NO_ERROR) break; // no more faces

PXCFaceAnalysis::Detection::Data face_data;
faceDetector->QueryData(fid, &face_data);
faceRender->SetDetectionData(&face_data);
faceRender->SetAttributeData(attributes,fid);

pxcU32 smile=0;
pxcU32 smileScore ;
pxcU32 genderScore=0;
// pxcU32 z;
pxcU32 scores[16];
pxcU32 scoresg[16];
pxcU32 scoresEmotion[16];
int mpidx= -1; pxcU32 maxscore= 0;

if(firstTime <4)
{
firstTime++; continue;
}

attributes->QueryData(PXCFaceAnalysis::Attribute::LABEL_AGE_GROUP,fid,scores);
for (int i=PXCFaceAnalysis::Attribute::INDEX_AGE_GROUP_BABY;i<=PXCFaceAnalysis::Attribute::INDEX_AGE_GROUP_SENIOR;i++) {
if (scores[i] < maxscore) continue;
// wprintf_s(L"\n inside Age Score is: %d",scores[i]);
maxscore=scores[i];

mpidx=i;
}

scoresg[0]=0;
scoresg[1]=0;

attributes->QueryData(PXCFaceAnalysis::Attribute::LABEL_GENDER,fid,scoresg);

bool isMale = (scoresg[0] > scoresg[1]);

if(scoresg[0] > scoresg[1])
{
genderScore=scoresg[0];
}
else
{
genderScore=scoresg[1];
}
wprintf_s(L"\nAge Score is: %d",maxscore);
wprintf_s(L"\n M:%d---F-%d----genderScoreFemale--%d and gender score male %d\n",isMale,!isMale,scoresg[1],scoresg[0]);

scoresEmotion[PXCFaceAnalysis::Attribute::INDEX_EMOTION_SMILE]=0;

pxcStatus sts=attributes->QueryData(PXCFaceAnalysis::Attribute::LABEL_EMOTION,fid,scoresEmotion);
// if (sts>=PXC_STATUS_NO_ERROR)
// {
bool isSmile=scoresEmotion[PXCFaceAnalysis::Attribute::INDEX_EMOTION_SMILE]>0;
smileScore = scoresEmotion[PXCFaceAnalysis::Attribute::INDEX_EMOTION_SMILE];
wprintf_s(L"Face is -----Smiling-%d------not Smiling--- --%dD------smileScore:%d\n",isSmile,!isSmile,smileScore);

// faceHttpHandler->handleFaceRequest(fid,mpidx,maxscore,isMale,genderScore,isSmile,smileScore,argv[1]);
// }

}

if (!faceRender->RenderFrame(images[0])) break;
}

return(0);

}

Still its not giving me correct result.

Its gives correct result for profile which is set first

ex

If I use like this

attributes->QueryProfile(PXCFaceAnalysis::Attribute::LABEL_GENDER,aInfoGender);
attributes->SetProfile(PXCFaceAnalysis::Attribute::LABEL_GENDER,aInfoGender);

attributes->QueryProfile(PXCFaceAnalysis::Attribute::LABEL_EMOTION,aInfoEmotion);
attributes->SetProfile(PXCFaceAnalysis::Attribute::LABEL_EMOTION,aInfoEmotion); 

attributes->QueryProfile(PXCFaceAnalysis::Attribute::LABEL_AGE_GROUP,aInfoAge);
attributes->SetProfile(PXCFaceAnalysis::Attribute::LABEL_AGE_GROUP,aInfoAge);

It gives correct output for gender but showing alwys smiling even if I am not and smile score is also 100.

Please find Attached screen for reference.

And please let me know if I am wrong while proccessing Images.

Thanks

Yogesh

Attachments: 

AttachmentSize
Download face-smile.png437.25 KB

Hi,

Please review this code and let me know if I there is  any mistake while proccessing face data.

Thanks

Yogesh.

whenever you use QueryProfile() use pidx = 0; If you leave this argument not initialized the function returns the current working profile previously set by setProfile. see below:

attributes->QueryProfile(PXCFaceAnalysis::Attribute::LABEL_GENDER, 0; aInfoGender);  //pidx = 0, not working profile.
do that for all the others.

let me know if this works.

 

Hi  Sadaka,

 Thank you very much for the solution its working now.

  I need your help with respect to proccessing video straem(Writing video stream into file)

 if I have this  video straem

 PXCCapture::VideoStream *videoStream=capture.QueryVideoStream(0);

 can you please suggest me some Document or link related to this proccessing.

Hi Sadaka,

Thank you very much for solution this is working now.

I am trying to process video Stream from capture device like write it into file as video
will you please let me know any suggestion related to this like Any API document for processing video.

Thanks
Yogesh.

it is possible to get other emotion than smile from PXCFaceAnalysis::Attribute ?

Login to leave a comment.