Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

the problem is NOT opencv's FaceRocognizer here, but that you train it on 200 instances of a single image !

let me show you:

java.util.List<Mat> list = new ArrayList<Mat>();
Mat img = new Mat(); // this is the problem

for(int i=0; i<5; i++){
    img.create(3,3,0);
    img.setTo(new Scalar(i));
    list.add(img); // they're all the same here !
}

for (Mat i:list) {
    cerr(i.dump());
}

 [java] [  4,   4;
 [java]    4,   4]
 [java] [  4,   4;
 [java]    4,   4]
 [java] [  4,   4;
 [java]    4,   4]
 [java] [  4,   4;
 [java]    4,   4]
 [java] [  4,   4;
 [java]    4,   4

remedy: use local variables in your for loop:

    for(File image : imageFiles){
        Mat img = Imgcodecs.imread(image.getAbsolutePath());
        Mat grayImg = new Mat();
        Imgproc.cvtColor(img, grayImg, Imgproc.COLOR_BGR2GRAY);  
        list.add(grayImg);
       ...

the problem is NOT opencv's FaceRocognizer here, but that you train it on 200 instances of a single image !

let me show you:

java.util.List<Mat> list = new ArrayList<Mat>();
Mat img = new Mat(); // this is the problem

for(int i=0; i<5; i++){
    img.create(3,3,0);
    img.setTo(new Scalar(i));
    list.add(img); // they're all the same here !
}

for (Mat i:list) {
    cerr(i.dump());
System.out.println(i.dump());
}

 [java] [  4,   4;
 [java]    4,   4]
 [java] [  4,   4;
 [java]    4,   4]
 [java] [  4,   4;
 [java]    4,   4]
 [java] [  4,   4;
 [java]    4,   4]
 [java] [  4,   4;
 [java]    4,   4

remedy: use local variables in your for loop:

    for(File image : imageFiles){
        Mat img = Imgcodecs.imread(image.getAbsolutePath());
        Mat grayImg = new Mat();
        Imgproc.cvtColor(img, grayImg, Imgproc.COLOR_BGR2GRAY);  
        list.add(grayImg);
       ...

the problem is NOT opencv's FaceRocognizer here, but that you train it on 200 instances of a singlethe same image !

let me show you:

java.util.List<Mat> list = new ArrayList<Mat>();
Mat img = new Mat(); // this is the problem

for(int i=0; i<5; i++){
    img.create(3,3,0);
    img.setTo(new Scalar(i));
    list.add(img); // they're all the same here !
! (no "deep copy")
}

for (Mat i:list) {
    System.out.println(i.dump());
}

 [java] [  4,   4;
 [java]    4,   4]
 [java] [  4,   4;
 [java]    4,   4]
 [java] [  4,   4;
 [java]    4,   4]
 [java] [  4,   4;
 [java]    4,   4]
 [java] [  4,   4;
 [java]    4,   4

remedy: use local variables in your for loop:

    for(File image : imageFiles){
        Mat img = Imgcodecs.imread(image.getAbsolutePath());
        Mat grayImg = new Mat();
        Imgproc.cvtColor(img, grayImg, Imgproc.COLOR_BGR2GRAY);  
        list.add(grayImg);
       ...