0

当它实际在目标图像上进行人脸识别时,试图找出一种方法来收集置信度。我已经搜索了一些示例,但没有找到任何我可以看到如何实现的东西。感谢所有帮助,谢谢大家。

public static void facecompare() {
    String trainingDir = "C:/TrainingDirectory";     //training directory
    IplImage testImage = cvLoadImage("C:/TargetImages/boland_straight_happy_open_4.pgm"); //the target image

    File root = new File(trainingDir);

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

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

    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());

        label = Integer.parseInt(image.getName().split("\\-")[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);



    // FaceRecognizer faceRecognizer = createFisherFaceRecognizer();
    // FaceRecognizer faceRecognizer = createEigenFaceRecognizer();
    FaceRecognizer faceRecognizer = createLBPHFaceRecognizer();

    faceRecognizer.train(images, labels);

    cvCvtColor(testImage, greyTestImage, CV_BGR2GRAY);

    int predictedLabel = faceRecognizer.predict(greyTestImage);

    System.out.println("Predicted label: " + predictedLabel);
}
4

1 回答 1

1

还有另一种返回置信度的预测方法:

// pointer-like output parameters
// only the first element of these arrays will be changed
int[] plabel = new int[1];
double[] pconfidence = new double[1];

faceRecognizer.predict(greyTestImage, plabel, pconfidence);

int predictedLabel = plabel[0];
double confidence = pconfidence[0];
于 2014-02-20T06:45:20.000 回答