Closed mousomer closed 7 years ago
Hi @mousomer,
yeah, sure it is possible. Actually, this is how it is done in the MATLAB and Python interfaces - the CFLandmark and CFeaturePool classes are initialized only once and reused each time new image is provided.
So, the fastest solution is to use the interfaces. Or you can rewrite the code such that it processes a list of images. I have some example for the video stream, which is doing exactly that. However, I probably won't be able to upload it sooner than in 2 weeks.
Well, yes, it certainly works:
` // initialization of C2F-DPM
string MODEL_CDPM = GetRunPath () + "../../" +modelDir + "/CDPM.xml";
string MODEL_FDPM = GetRunPath () + "../../" +modelDir + "/FDPM.xml";
string MODEL_AFLW_N_PROF = GetRunPath () + "../../" +modelDir + "PART_fixed_JOINTMV_-PROFILE.xml";
string MODEL_AFLW_HN_PROF = GetRunPath () + "../../" +modelDir + "PART_fixed_JOINTMV_-HALF-PROFILE.xml";
string MODEL_AFLW_FRONT = GetRunPath () + "../../" +modelDir + "PART_fixed_JOINTMV_FRONTAL.xml";
string MODEL_AFLW_HP_PROF = GetRunPath () + "../../" +modelDir + "PART_fixed_JOINTMV_HALF-PROFILE.xml";
string MODEL_AFLW_P_PROF = GetRunPath () + "../../" +modelDir + "PART_fixed_JOINTMV_PROFILE.xml";
string AFLW_extentions[5] = {
"NegProf",
"NegHProf",
"Frontal",
"PosHProf",
"PosProf" };
Flandmark *CDPM = Flandmark::getInstanceOf (MODEL_CDPM.c_str ());
Flandmark *FDPM = Flandmark::getInstanceOf (MODEL_FDPM.c_str ());
Flandmark *AFLW_NP = Flandmark::getInstanceOf (MODEL_AFLW_N_PROF.c_str ());
Flandmark *AFLW_PP = Flandmark::getInstanceOf (MODEL_AFLW_P_PROF.c_str ());
Flandmark *AFLW_NHP = Flandmark::getInstanceOf (MODEL_AFLW_HN_PROF.c_str ());
Flandmark *AFLW_PHP = Flandmark::getInstanceOf (MODEL_AFLW_HP_PROF.c_str ());
Flandmark *AFLW_F = Flandmark::getInstanceOf (MODEL_AFLW_FRONT.c_str ());
c_prof.Start(pf_classesC);
const int * bw_sizeC = CDPM->getBaseWindowSize();
CFeaturePool * featuresPoolCDPM = new CFeaturePool(bw_sizeC[0], bw_sizeC[1]);
featuresPoolCDPM->addFeaturesToPool( new CSparseLBPFeatures(featuresPoolCDPM->getWidth(), featuresPoolCDPM->getHeight(),
featuresPoolCDPM->getPyramidLevels(), featuresPoolCDPM->getCumulativeWidths()));
CDPM->setNFfeaturesPool(featuresPoolCDPM);
printf("init Coarse DPM %d x %d \n", bw_sizeC[0], bw_sizeC[1] );
const int * bw_sizeF = FDPM->getBaseWindowSize();
CFeaturePool * featuresPoolFDPM = new CFeaturePool(bw_sizeF[0], bw_sizeF[1]);
featuresPoolFDPM->addFeaturesToPool(new CSparseLBPFeatures( featuresPoolFDPM->getWidth(), featuresPoolFDPM->getHeight(),
featuresPoolFDPM->getPyramidLevels(), featuresPoolFDPM->getCumulativeWidths()));
FDPM->setNFfeaturesPool(featuresPoolFDPM);
printf("init Fine DPM %d x %d \n", bw_sizeF[0], bw_sizeF[1] );
const int * bw_size = AFLW_F->getBaseWindowSize();
CFeaturePool * featuresPoolAFLW = new CFeaturePool(bw_size[0], bw_size[1]);
featuresPoolAFLW->addFeaturesToPool(new CSparseLBPFeatures( featuresPoolAFLW->getWidth(), featuresPoolAFLW->getHeight(),
featuresPoolAFLW->getPyramidLevels(), featuresPoolAFLW->getCumulativeWidths()));
AFLW_NP->setNFfeaturesPool(featuresPoolAFLW);
AFLW_PP->setNFfeaturesPool(featuresPoolAFLW);
AFLW_NHP->setNFfeaturesPool(featuresPoolAFLW);
AFLW_PHP->setNFfeaturesPool(featuresPoolAFLW);
AFLW_F->setNFfeaturesPool(featuresPoolAFLW);
Flandmark* FL_JA[5] = {AFLW_NP, AFLW_NHP, AFLW_F, AFLW_PHP, AFLW_PP};`
And then a call to the detect function with the model pointer array. Runtime is much better.
I am testing the CDPM / FDPM on detected faces - using you snippet from http://cmp.felk.cvut.cz/~uricamic/clandmark/index.php?page=snippets#snippets-C2F-DPM. I am testing a large pool of images with pre-detected faces, and I want to loop over the faces. Doing new/delete on every face is very costly. Can I reuse the FeaturePool classes?