Face Recognition

Face Recognition

In sdkmanual-face.pdf,  page 14, example 9: Calculate Similarity of Two Faces, the method PXCFaceAnalysis::Recognition::Model *createModelFromImage(PXCImage *image)

PXCSmartSP sp;
face->ProcessImageAsync(&image,&sp);
sp->Synchronize();

My program encounters an access violation when executing the third line sp->Synchronize(),  anyone know why? Thanks very much!

4 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione

Most probably PXCFaceAnalysis or PXCImage object was not initialized correctly. But program should not crash anyway.
Can you provide either
- source code how you create and configure PXCFaceAnalysis
- program in binary form
to reproduce that?

Thanks for reporting.

Citazione:

Mikhail Nikolsky (Intel) ha scritto:

Most probably PXCFaceAnalysis or PXCImage object was not initialized correctly. But program should not crash anyway.
Can you provide either
- source code how you create and configure PXCFaceAnalysis
- program in binary form
to reproduce that?

Thanks for reporting.

The following is my source code to create PXCImage from local images and then use PXCFaceAnalysis to process them and use IsSimilar to judge whether the two images have the same faces.
It encounters access violation in this line "faceAnalyzer->DynamicCast()->CreateModel(fid,&m1); "
BTW, the function LoadImageFromLocal actually works for the convert, but in this line "pxcStatus sts = accelerator->CreateImage(&info, 0, &data, *dst_img);", the pxcStatus it returns is -2, when you ignore it the image convert seems ok. isn't -2 means there're unsupported parameters? Then why it seems works fine?

#include "pxcsmartptr.h"
#include "util_cmdline.h"
#include "pxcface.h"
#include "cv.h"
#include "highgui.h"
using namespace cv;
PXCSmartPtr faceAnalyzer;
void LoadImageFromLocal(PXCImage **dst_img, const char * path){

IplImage *image = cvLoadImage(path);
unsigned char *rgb_data;
int rgb_pitch = image->widthStep; // bytes between image lines
rgb_data = (unsigned char*)image->imageData;
PXCSession *session;
PXCSession_Create(&session);
PXCAccelerator * accelerator;
session->CreateAccelerator(PXCAccelerator::ACCEL_TYPE_CPU, &accelerator);// *session = 0;
//session->CreateAccelerator(PXCAccelerator::ACCEL_TYPE_CPU, &accelerator);
PXCImage::ImageInfo info;
memset(&info, 0, sizeof(info));
info.height = image->height;
info.width = image->width;
info.format = PXCImage::COLOR_FORMAT_RGB24;
PXCImage::ImageData data;
memset(&data, 0, sizeof(data));
data.format = PXCImage::COLOR_FORMAT_RGB24;
data.planes[0] = rgb_data;
data.pitches[0] = rgb_pitch;

pxcStatus sts = accelerator->CreateImage(&info, 0, &data, dst_img);
}

PXCFaceAnalysis::Recognition::Model *createModelFromImage(PXCImage *image) {
PXCSmartSP sp;
faceAnalyzer->ProcessImageAsync(&image,&sp);
sp->Synchronize();
pxcUID fid;
faceAnalyzer->QueryFace(0,&fid);
PXCFaceAnalysis::Recognition::Model *m1=0;
faceAnalyzer->DynamicCast()->CreateModel(fid,&m1);
return m1;

}
bool IsSimilar(PXCImage *image1, PXCImage *image2) {
PXCFaceAnalysis::Recognition::Model *ref=createModelFromImage(image1);
PXCFaceAnalysis::Recognition::Model *cur=createModelFromImage(image2);
pxcU32 index;
return cur->Compare(&ref,1,0,&index)>=PXC_STATUS_NO_ERROR;
}
int wmain(int argc, wchar_t* argv[]) {
PXCImage *img1, *img2;
const char * imagePath1 = "images/oldman.png";
const char * imagePath2 = "images/girl.jpg";
LoadImageFromLocal(&img1, imagePath1);
LoadImageFromLocal(&img2, imagePath2);

// Create a session
PXCSmartPtr session;
pxcStatus sts=PXCSession_Create(&session);
if (sts faceAnalyzer;*/
sts=session->CreateImpl(cmdl.m_iuid, PXCFaceAnalysis::CUID, (void**)&faceAnalyzer);
if (sts

Best Reply

There are at least two critical problems in this code.

First, you can't pass data (PXCImage, etc) across different sessions. Typically application creates only one PXCSession. It’s easy to fix, just pass existent PXCSession to LoadImageFromLocal function.

Second, every module instance should be initialized by calling SetProfile function. You can use QueryProfile with index=0 to obtain first supported configuration. Below is code example for setting face detection and face recognition configurations:


    PXCFaceAnalysis::ProfileInfo faInfo;

    faceAnalyzer->QueryProfile(0, &faInfo);

    faceAnalyzer->SetProfile(&faInfo);
    PXCFaceAnalysis::Recognition *faceRecognizer = faceAnalyzer->DynamicCast();

    PXCFaceAnalysis::Recognition::ProfileInfo recInfo;

    faceRecognizer->QueryProfile(0, &recInfo);

    faceRecognizer->SetProfile(&recInfo);

BTW, the CreateImage function returned error code because data.type not initialized (union planes[]/surfaceHandle in PXCImage structure depends on this field). For system memory buffers, set data.type = PXCImage::SURFACE_TYPE_SYSTEM_MEMORY.

Accedere per lasciare un commento.