0

I am doing a project on face recognition on java.For that i am using opencv library.But i don't know how to call the facerecognition method from opencv directly without any other libraries.So now i am using javacv for that purpose.But when i tried the code,these two lines shows red line.
FaceRecognizer faceRecognizer = createEigenFaceRecognizer(); . MatVector images = new MatVector(imageFiles.length);

I tried to import the corresponding packages but it won't works.can anyone help me? If anyone know how to implement facerecognition only with opencv library then plzz help me.Thanks in advance.

My code:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Work;

/**
 *
 * @author user
 */
import com.googlecode.javacv.cpp.opencv_core;
import static com.googlecode.javacv.cpp.opencv_highgui.*;
import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_contrib.*;
import java.io.File;
import java.io.FilenameFilter;

public class OpenCVFaceRecognizer {
public static void main(String[] args) {
    String trainingDir = "C:/Users/reco/workspace/hellow";

    IplImage testImage = cvLoadImage("C:/Users/reco/workspace/0.png");

    File root = new File(trainingDir);

    FilenameFilter pngFilter = new FilenameFilter() {
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".png");
        }
    };

    File[] imageFiles = root.listFiles(pngFilter);

//shows red line
         MatVector images = new MatVector(imageFiles.length);

    int[] labels = new int[imageFiles.length];

    int counter = 0;
    int label;

    IplImage img;
    IplImage grayImg;

    for (File image : imageFiles) {
        img = cvLoadImage(image.getAbsolutePath());
        String temp= image.getName();
        label = Integer.parseInt(temp.charAt(0)+"");

        grayImg = IplImage.create(img.width(), img.height(), IPL_DEPTH_8U, 1);

        cvCvtColor(img, grayImg, CV_BGR2GRAY);

        images.put(counter, grayImg);

        labels[counter] = label;

        counter++;
    }

    IplImage greyTestImage = IplImage.create(testImage.width(), testImage.height(), IPL_DEPTH_8U, 1);



//shows red line
         FaceRecognizer faceRecognizer = createEigenFaceRecognizer();



  faceRecognizer.train(images, labels);

    cvCvtColor(testImage, greyTestImage, CV_BGR2GRAY);

    int predictedLabel = faceRecognizer.predict(greyTestImage);

    System.out.println("Predicted label: " + predictedLabel);
}
}
  • 1
    What is the actual compiler error that you are getting? – DNA Feb 15 '15 at 16:20
  • The error is "cannot find symbol createeigenfacerecognizer in class opencvfacerecognizer" – user3831796 Feb 15 '15 at 16:22
  • Did you make sure you included the necessary JARs that JavaCV refers to in your `CLASSPATH`? – rayryeng Feb 15 '15 at 17:34
  • See also [this question](https://stackoverflow.com/questions/11699744/face-recognition-on-android) which involves exactly the same code example – DNA Feb 15 '15 at 17:43
  • i have imported javacv and opencv jars into the program. – user3831796 Feb 16 '15 at 04:06
  • @DNA : Is it possible to add the code from javacv ([link]https://stackoverflow.com/questions/11699744/face-recognition-on-android) directly to our java application? – user3831796 Feb 16 '15 at 04:23

0 Answers0