FaceRecognizer - train method throws "Assertion failed"

1,448 views
Skip to first unread message

Leandro Diato

unread,
Oct 22, 2012, 12:51:22 PM10/22/12
to jav...@googlegroups.com
Hi,
 I am trying to do face reconition using the new functionality from FaceRecognizer. I have read all the post about it and couldn't found an example (using javaCV, not C++) of how to do it from scratch.


This is my code for learning process. I am using 6 pictures of the same person (person number 1)

public void learn(String imgFilename ){
  int numberOfFacesToLearn = 6;
  MatVector images = new MatVector(numberOfFacesToLearn);
  CvMat labels = CvMat.create(numberOfFacesToLearn, 1, CV_32SC1); 
  for( int i = 0; i < numberOfFacesToLearn ; i++){
    IplImage faceImgArr = cvLoadImage(imgFilename + i, //all the file names are valid 
                                       CV_LOAD_IMAGE_GRAYSCALE);
    images.put(faceImgArr);
    labels.put(i, 0, 1); //I'm not sure about this line. "1" is because the user number is the same for all the pictures.
  }

  FaceRecognizerPtr model = createLBPHFaceRecognizer(1, 8, 8, 8, Double.MAX_VALUE);
  FaceRecognizer reco = model.get();
  reco.train(images, labels);
}

Every step goes well until the last line (reco.train(images, labels);) when I got this exception:

OpenCV Error: Assertion failed (s >= 0) in unknown function, file ..\..\..\src\opencv\modules\core\src\matrix.cpp, line 115
10-22-12.09:23:37,896-main-ERROR-OpencvClient:Unexpected error: 
java.lang.RuntimeException: ..\..\..\src\opencv\modules\core\src\matrix.cpp:115: error: (-215) s >= 0
at com.googlecode.javacv.cpp.opencv_contrib$FaceRecognizer.train(Native Method)


I'll appreciate if somebody can help me to fix this error . I am stuck with this issue since a few days and I dont know how to resolve it at all.

Thanks

Leandro Diato

unread,
Oct 22, 2012, 3:26:52 PM10/22/12
to jav...@googlegroups.com
I can fix it, the problem was that I should use "cvLoadImageM" instead of "cvLoadImage"

Now the training process seems to be working:

public void learn(String imgFilename ){
  int numberOfFacesToLearn = 6;
  MatVector images = new MatVector(numberOfFacesToLearn);
  CvMat labels = CvMat.create(1, numberOfFacesToLearn, CV_32SC1);
  for(int i = 0; i < numberOfFacesToLearn; i++){
  CvMat faceImg = cvLoadImageM(imgFilename + i, //all the file names are valid 
                                       CV_LOAD_IMAGE_GRAYSCALE);
    images.put(i, faceImg);
    labels.put(i, 1);
  }

  this.model = createEigenFaceRecognizer(numberOfFacesToLearn, Double.MAX_VALUE);
  this.reco = model.get();
  this.reco.train(images, labels);
}


I have some doubts about how to set a correct threshold value. But I will create a new post for that.

Thanks

Samuel Audet

unread,
Oct 28, 2012, 3:45:05 AM10/28/12
to jav...@googlegroups.com
Hello,

That shouldn't change anything. There is some code here that works just
fine with cvLoadImage() for example:
http://code.google.com/p/javacv/issues/detail?id=211

tech...@gmail.com

unread,
Aug 25, 2014, 3:43:44 AM8/25/14
to jav...@googlegroups.com


Hello,I have the same problem like that,but my program is SVM object detect.
the program always cash at "hog.detectMultiScale(img, found, 0, Size(8,8), Size(32,32), 1.05, 2);"
It always say that"OpenCV Error: Assertion failed (s >= 0) in unknown function".
Did you find the solution at this problem? Thanks

by the way , sorry for my poor english.......

Samuel Audet

unread,
Aug 30, 2014, 1:13:19 AM8/30/14
to jav...@googlegroups.com
On 08/25/2014 04:43 PM, tech...@gmail.com wrote:
> Hello,I have the same problem like that,but my program is SVM object detect.
> the program always cash at "hog.detectMultiScale(img, found, 0, Size(8,8), Size(32,32), 1.05, 2);"
> It always say that"OpenCV Error: Assertion failed (s >= 0) in unknown function".
> Did you find the solution at this problem? Thanks

That just means the "scale factor" can't be 0. Try a larger value

Samuel

Reply all
Reply to author
Forward
0 new messages