1

In the FaceRecognition class from java jni I have the following train method:

public  void train(List<Mat> src, Mat labels)

In all the examples "labels" is a vector, not a Mat. In the c++ documentation I did found:

The labels of each image are stored within a std::vector<int> (you could also use a Mat of type CV_32SC1).

but I'm not sure how to do this in java. How do I construct a Mat of type CV_32SC1 that contains a list of int?

1 Answer 1

2

I was able to figure it out in the end:

List<Mat> src = new ArrayList<>();

Mat image = Highgui.imread("faces/s1/1.pgm", 0);
src.add(image);

image = Highgui.imread("faces/s1/2.pgm", 0);
src.add(image);

image = Highgui.imread("faces/s1/3.pgm", 0);
src.add(image);

image = Highgui.imread("faces/s1/4.pgm", 0);
src.add(image); 

image = Highgui.imread("faces/s2/1.pgm", 0);
src.add(image);

image = Highgui.imread("faces/s2/2.pgm", 0);
src.add(image);

image = Highgui.imread("faces/s2/3.pgm", 0);
src.add(image);

image = Highgui.imread("faces/s2/4.pgm", 0);
src.add(image);   

Mat labels = new Mat(8, 1, CvType.CV_32SC1);
labels.put(0, 0, 1);
labels.put(1, 0, 1);
labels.put(2, 0, 1);
labels.put(3, 0, 1);
labels.put(4, 0, 2);
labels.put(5, 0, 2);
labels.put(6, 0, 2);
labels.put(7, 0, 2);

FaceRecognizer recognizer = new LBPHFaceRecognizer();
recognizer.train(src, labels);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.