这是我的代码
#include "facerec.h"
Ptr<FaceRecognizer> jarvis;
void initJarvis(){
jarvis=createEigenFaceRecognizer();
//jarvis->set("threshold",6000);
if(fileExists("jarvis-data.xml")){
jarvis->load("jarvis-data.xml");
}
}
void saveJarvisData(){
jarvis->save("jarvis-data.xml");
}
/*void trainJarvis(int id){
vector<Mat> images;
vector<int> labels;
int pno;
char debugout[100];
char imgpath[30];
FILE *fp=fopen("imglist.txt","r");
while(fscanf(fp,"%d %s",&pno,imgpath)==2){
if(pno==id){
sprintf(debugout,"%d %s\n",pno,imgpath);
OutputDebugStringA(debugout);
images.push_back(imread(imgpath,CV_LOAD_IMAGE_GRAYSCALE));
labels.push_back(pno);
}
}
fclose(fp);
try{
jarvis->train(images,labels);
}catch(Exception e){
char msg[100];
sprintf(msg,"%s",e.msg);
MessageBoxA(NULL,msg,"error",0);
}
}
*/
void trainJarvis(){
vector<Mat> images;
vector<int> labels;
int pno;
char debugout[100];
char imgpath[30];
FILE *fp=fopen("imglist.txt","r");
while(fscanf(fp,"%d %s",&pno,imgpath)==2){
sprintf(debugout,"%d %s\n",pno,imgpath);
OutputDebugStringA(debugout);
images.push_back(imread(imgpath,CV_LOAD_IMAGE_GRAYSCALE));
labels.push_back(pno);
}
fclose(fp);
try{
jarvis->train(images,labels);
}catch(Exception e){
char msg[100];
sprintf(msg,"%s",e.msg);
MessageBoxA(NULL,msg,"error",0);
}
}
int recognize(){
double confidence;
int label=-1;
Mat img=imread("image.jpg",CV_LOAD_IMAGE_GRAYSCALE);
int prediction;
try{
jarvis->predict(img,prediction,confidence);
}catch(Exception e){
char msg[100];
sprintf(msg,"%s",e.msg);
MessageBoxA(NULL,msg,"error",0);
}
char temp[40];
sprintf(temp,"Label : %d \nConfidence : %f",prediction,confidence);
MessageBoxA(NULL,temp,"Prediction",0);
return prediction;
}
我已经存储了15个灰度图像。为此我跟着shervin emamis tutorial 我得到4000-8000的置信度
如何让它更准确地预测面孔