About model serialize and deserialize

About model serialize and deserialize

In face recognition, I want to serialize the face models and store it in a file, then when an image with a face is provided, I create its model and search it among the deserialized models. Below is the serialize/deserialize function pair I've wrote:

const long buffSize = 100000;
void SerializeModelsFromImages(const char *refPathName, PXCImage *images[], int num){
 ofstream outputfile(refPathName, ofstream::binary);
 for(int i = 0; i < num; ++i){
   PXCFaceAnalysis::Recognition::Model * model = createModelFromImage(images[i]);
   pxcBYTE *buffer = new pxcBYTE[buffSize];
   model->Serialize(buffer);
   outputfile.write((const char*)buffer, buffSize);
 }
 outputfile.close();
}
vector<PXCFaceAnalysis::Recognition::Model *> DeserializeReferenceModels(const char* refPathName, int &sizeRefArray){ vector<PXCFaceAnalysis::Recognition::Model*> refModels; 
 ifstream inputfile(refPathName, ifstream::binary);
 long size;
 char *buffer = new char[buffSize];
 inputfile.seekg(0, ifstream::end);
 size = inputfile.tellg();
 sizeRefArray = size / buffSize;
 inputfile.seekg(0, ifstream::beg);
 for(int i = 0; i < sizeRefArray; ++i){
   inputfile.read(buffer, buffSize);
   PXCFaceAnalysis::Recognition::Model *ref;
   faceAnalyzer->DynamicCast<PXCFaceAnalysis::Recognition>()->DeserializeModel((pxcBYTE*)buffer, &ref);
   refModels.push_back(ref);
 } 
 return refModels;
}
pxcU32 FaceRecognition(vector<PXCFaceAnalysis::Recognition::Model *> refModelsArray, PXCImage* image){
 PXCFaceAnalysis::Recognition::Model *cur = createModelFromImage(image);
 pxcU32 index;
 int sizeRefArray = refModelsArray.size();
 PXCFaceAnalysis::Recognition::Model ** refModels = new PXCFaceAnalysis::Recognition::Model*[sizeRefArray];
 for(int i = 0; i < sizeRefArray; ++i)
   refModels[i] = refModelsArray[i];
 if(cur->Compare(refModels, sizeRefArray, 0, &index) >= PXC_STATUS_NO_ERROR)
   return index;
}

my question:

The serialize and deserialize function seems works ok, but when calling FaceRecognition function it encounters some problem in the underlined line---"if(cur->Compare(refModels, sizeRefArray, 0, &index) >= PXC_STATUS_NO_ERROR)" with memory access violation. I've check the parameter in Compare, they are not NULL or invalid.

Is the probem to do with char * buffer and pxcBYTE*  buffer that makes deserialize process works wrong? or something else? Thanks very much!

2 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

Problem solved, when calling Compare(refModels, sizeRefArray, 0, &index) with refModels more than one model, the third parameter should be given int * score instead of 0 and it should be allocated memory outside.

Now my program works fine, but the sometime the most similar face index returned was wrong, so the pxc sdk still have to do a little more analysis about human face and thus seizes the most discriminating features about human face no matter the gesture, emotion or even face direction.

Connectez-vous pour laisser un commentaire.