OpenCV - predict_label returns a huge value

asked 2017-05-19 13:52:15 -0500

Syed Hasnain gravatar image

updated 2017-05-19 14:27:07 -0500

berak gravatar image

I have trained faceRecognizer in Java. But when i predict a label it returns a huge value which is not the actual label which i stored during training. Please have a look at my training code and tell me how this error can be resolved.

String trainingDir = "res/";
        File root = new File(trainingDir);
        FilenameFilter imgFilter = new FilenameFilter() {
            public boolean accept(File dir, String name) {
                name = name.toLowerCase();
                return name.endsWith(".jpg") || name.endsWith(".pgm") || name.endsWith(".png");
    File[] imageFiles = root.listFiles(imgFilter);
    ArrayList <mat> images = new ArrayList(imageFiles.length);
    Mat labels = new Mat(imageFiles.length,1,CvType.CV_32SC1);
    ArrayList <integer>labelsBuf = new ArrayList<>(imageFiles.length);

    int counter =0;
    for(File image: imageFiles){
        Mat img = Imgcodecs.imread(image.getAbsolutePath(),Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
        int label = Integer.parseInt(image.getName().split("\\.")[2]);
        //images.add(label, img);
        labelsBuf.add(counter, label); 
    FaceRecognizer faceRecognizer = Face.createFisherFaceRecognizer();

    faceRecognizer.train(images, labels);

Thanks in advance

edit retag flag offensive close merge delete