1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
for(int k=0; k<NUMBER_OF_PERSON; k++)
{
for(int i=0; i<NUMBER_OF_CLASSES; i++)
{
for(int j=0; j<NUMBER_OF_SAMPLE_PER_CLASS ; j++)
{
//cout<<"Learning Sample N°: " << nbSample <<endl;
string stra = "D:/CrossValidationRandom";
ostringstream oi;
ostringstream oj;
ostringstream ok;
ok << k;
oi << i;
oj << j;
string NPerson = ok.str();
string NClass = oi.str();
string NSample = oj.str();
string ImgPath = stra + "/" + NPerson + "/" + NClass + "/" + NSample + ".tiff";
IplImage* Src = cvLoadImage(ImgPath.c_str());
IplImage* FaceImg = cvCreateImage(cvSize(FACE_WIDTH, FACE_HEIGHT), IPL_DEPTH_8U, 1);
FE.FaceDetection(Src, FaceImg);
cvReleaseImage(& Src);
//Features Extraction
int* LBPHist = new int[NbBins];//(int*)malloc(NbBins * sizeof(int));
FE.LBPFeatureExtraction(FaceImg, NbSegment, NbImage, LBPHist);
//Stoquer les features de toute les images d'apprentissage
for(int m=0; m<NbBins; m++) { LBPData[nbFeat++] = LBPHist[m]; }
delete[] LBPHist; //LBPHist = NULL;
Class[nbSample] = i;
nbSample++;
}
}
}
cvInitMatHeader (&data_mat, NUMBER_OF_TRAINING_SAMPLES, NbBins, CV_32FC1, LBPData);
cvInitMatHeader (&Class_mat, NUMBER_OF_TRAINING_SAMPLES, 1, CV_32SC1, Class);
param.svm_type = CvSVM::C_SVC;
param.kernel_type = CvSVM::LINEAR;
param.term_crit = cvTermCriteria(CV_TERMCRIT_ITER, 100, 1e-6);
cout<<"Start Training SVM"<<endl;
svm.train (&data_mat, &Class_mat, Mat(), Mat(), param);
svm.save ("C:\Train.xml");
cout<<"Fin Apprentissage SVM"<<endl;
//Free Memory
delete[] LBPData;
delete[] Class;
cvDecRefData(& data_mat);
cvDecRefData(& Class_mat); |
Partager