getting openCv error- Image step is wrong in EigenFaces.Predict() method
I am getting error in EigenFaces.predict() method in java cv face recognition. The error is-
OpenCV Error: Image step is wrong (The matrix is not continuous, thus its number of rows can not be changed) in unknown function, file ......\src\opencv\modules\core\src\matrix.cpp, line 802
my code is-
public static void main(String[] args) {
long size=6;
MatVector imgs=new MatVector(size);
int[] id={0,0,0,0,0,0};
FaceRecognizer fr=opencv_contrib.createEigenFaceRecognizer();
for(int i=0;i<=5;i++)
{
String url="C:/Users/vivek/Documents/NetBeansProjects/Recognizer2/src/a"+(i+1)+".jpg";
IplImage img=opencv_highgui.cvLoadImage(url);
imgs=imgs.put(i,img);
}
fr.train(imgs,id);
IplImage testImage=opencv_highgui.cvLoadImage("C:/Users/vivek/Documents/NetBeansProjects/Recognizer2/src/a3.jpg");
CvMat mat= testImage.asCvMat();
int val=fr.predict(mat);
System.out.println(val);
}
All images are preprocessed, grey scaled and of same size(70*70). I am using open cv-2.4.7.
when I am using LBPfaceRecognizer, it gives error- OpenCV Error: The function/feature is not implemented (Using Original Local Binary Patterns for feature extraction only works on single-channel images (given 16) Please pass the image data as a grayscale image!)
after loading the images, convert them (both test & train imges !) to grayscale. this might solve both of your problems
@berak Images are already gray scaled. but I tried it again- IplImage imga=new IplImage(); opencv_imgproc.cvCvtColor(img, imga,opencv_imgproc.CV_RGB2GRAY); it gives error- OpenCV Error: Bad argument (Unknown array type) in unknown function,
you probably need to give valid size & type to imga when constructing it.
also, when you cvLoadImage("bl2bl2") - it loads images as 3 channel( 3*grey in your case, probably)
@berak then how to load it as 1 channel??
there's a flag for cvLoadImage(), no idea about javacv
Ok it is working fine with LBPH FaceRecognizer but getting same eeror message for EigenFaceRecognizer.