我正在使用JavaCV 1.1从here开发人脸识别,选择LBPH识别器,当程序运行时显示来自training文件夹的预测图像编号。
例如:如果文件夹包含以下图像:steve1.png,steve2.png和judy3.png,judy4.png和要分类的人是judy,打印
Predicted label: 4
这意味着该人来自judy4.png
我想展示" judy"作为预测标签。
用于显示预测标签的方法返回一个int,需要是一个String
faceRecognizer.predict(personToClassify);
这里是涉及问题的代码:
MatVector images = new MatVector(imageFiles.length);
Mat labels = new Mat(imageFiles.length, 1, CV_32SC1);
IntBuffer labelsBuf = labels.getIntBuffer();
int counter = 0;
for (File image : imageFiles) {
Mat img = imread(image.getAbsolutePath(), CV_LOAD_IMAGE_GRAYSCALE);
int label = Integer.parseInt(image.getName().split("\\-")[0]);
images.put(counter, img);
labelsBuf.put(counter, label);
counter++;
}
FaceRecognizer faceRecognizer = createFisherFaceRecognizer();
// FaceRecognizer faceRecognizer = createEigenFaceRecognizer();
// FaceRecognizer faceRecognizer = createLBPHFaceRecognizer()
faceRecognizer.train(images, labels);
int predictedLabel = faceRecognizer.predict(testImage);
System.out.println("Predicted label: " + predictedLabel);