Ask Your Question
0

getting openCv error- Image step is wrong in EigenFaces.Predict() method

asked 2013-12-23 04:01:28 -0600

vivek0402 gravatar image

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);

}

edit retag flag offensive close merge delete

Comments

All images are preprocessed, grey scaled and of same size(70*70). I am using open cv-2.4.7.

vivek0402 gravatar imagevivek0402 ( 2013-12-23 04:02:26 -0600 )edit

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!)

vivek0402 gravatar imagevivek0402 ( 2013-12-23 04:03:00 -0600 )edit

after loading the images, convert them (both test & train imges !) to grayscale. this might solve both of your problems

berak gravatar imageberak ( 2013-12-23 04:43:16 -0600 )edit

@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,

vivek0402 gravatar imagevivek0402 ( 2013-12-23 05:04:46 -0600 )edit

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 gravatar imageberak ( 2013-12-23 05:29:48 -0600 )edit

@berak then how to load it as 1 channel??

vivek0402 gravatar imagevivek0402 ( 2013-12-23 05:56:52 -0600 )edit

there's a flag for cvLoadImage(), no idea about javacv

berak gravatar imageberak ( 2013-12-23 06:44:48 -0600 )edit

Ok it is working fine with LBPH FaceRecognizer but getting same eeror message for EigenFaceRecognizer.

vivek0402 gravatar imagevivek0402 ( 2013-12-24 00:03:15 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-12-25 06:02:59 -0600

vivek0402 gravatar image

updated 2013-12-25 06:04:39 -0600

Finally I got the solution of my problem. The size of my test and training images were 70* 70. I changed the size to 200* 200 and now it is working perfectly. The reason behind it is that EigenFaceRecognizer and FisherFaceRecognizer don't work with image width that are not multiple of 8 or 16(In my case). 70 is not multiple of 8 so it is not working but for image width 200(multiple of 8), it is working fine.

edit flag offensive delete link more

Comments

THank you, it work in my project. But i wonder, we have a other scale?

jackauk gravatar imagejackauk ( 2015-06-22 23:55:00 -0600 )edit

Question Tools

Stats

Asked: 2013-12-23 04:01:28 -0600

Seen: 4,289 times

Last updated: Dec 25 '13