Reputation: 654
I am stuck in recognizing face please help me out,below is my code
FaceRecognizer faceRecognizer = com.googlecode.javacv.cpp.opencv_contrib.createFisherFaceRecognizer();
My Train method
public void train(){
IplImage img;
IplImage grayImg;
if(nameList!=null && nameList.size()>0){
for (int i = 0; i < nameList.size(); i++) {
String p = mPath+"person0/"+i+".png";
img = cvLoadImage(p);
labels[i] = i;
grayImg = IplImage.create(img.width(), img.height(), IPL_DEPTH_8U, 1);
cvCvtColor(img, grayImg, CV_BGR2GRAY);
images.put(i, grayImg);
}
}
faceRecognizer.train(images,labels);
}
My Predict Method
public void predict(){
String testPath = mPath+"test/person1.png";
Mat img = imread(testPath);
IplImage ipl = MatToIplImage(img,img.width(), img.width());
int predicted = faceRecognizer.predict(ipl);
Log.v(TAG," predicted : "+predicted);
}
for checking purpose I am using sample image without using device camera,my problem is the predict method gives same result for all sample,please guide me where am i doing mistake
Upvotes: 1
Views: 1798
Reputation: 186
After examining your code, I see a problem in how you collect labels. In this labels[i] = i;
statement, you are setting one different label for each image you read. I think you have multiple images per person. Labels are numeric values (think of them like a code) assigned to each PERSON and not each IMAGE. If you had two persons with each having 3 images, label should be having values [0, 0, 0, 1, 1, 1].
Another possible problem you should check is that all images MUST be of the SAME size. This means every image you are reading in the loop must have same size AND also images used in predict
must have same size. A good way to do that is by defining a fixed size, then resize every image you read to that fixed one.
Last problem I can think of is to use grayscale images only. Train method doesn't use color images. So same as image size, as soon as you read image, convert it to grayscale.
Further you can look at Face Recognition on Android and Face recognition using OpenCV in android?
Upvotes: 2