OpenCV人脸检测找不到任何

时间:2014-03-12 07:49:17

标签: java opencv face-detection

我已经按照在线教程设法写了一个这样的简单类:

public class FaceDetector
{

    public static void detect(String imageFile) {

        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        System.out.println("\nRunning FaceDetector");

        CascadeClassifier faceDetector = new CascadeClassifier(FaceDetector.class.getResource("haarcascade_frontalface_alt.xml").getPath());
        Mat image = Highgui.imread(imageFile);

        MatOfRect faceDetections = new MatOfRect();
        faceDetector.detectMultiScale(image, faceDetections);

        int faceCount = faceDetections.toArray().length;
        System.out.println(String.format("Detected %s faces", faceCount));

        for (Rect rect : faceDetections.toArray()) {
            Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
                    new Scalar(0, 255, 0));
        }

        String filename = imageFile+"_output.png";
        System.out.println(String.format("Writing %s", filename));
        Highgui.imwrite(filename, image);
    }
}

然而,我已尝试使用超过200张个人资料图片而无法检测到单个图片。由于它重写图像文件不变,我知道它正确读取图像。它没有给出任何错误。我现在应该怎么做?任何重定向?我应该在哪里阅读?我错过了什么?

1 个答案:

答案 0 :(得分:3)