One face can not be detected in an image with six faces

asked 2019-02-25 11:19:24 -0500

ray4 gravatar image

updated 2019-02-26 09:05:33 -0500

supra56 gravatar image

I am testing OpenCV and I have used multiple images of faces. One image does not get one of the faces out of six. I am using the picture of the Friends show with all six friends in the picture. Chandler can not be found in the picture. I have cut his face out into an individual picture. OpenCV still can not detect his face. What is wrong with his face? I'm programming with the Java API on a Windows 10 machine image description

Here is my code

private static void detectFaces(CascadeClassifier faceDetector, String inputFileName) {     
        Mat image = Imgcodecs.imread(inputFileName);         
        MatOfRect faceDetections = new MatOfRect(); 
        faceDetector.detectMultiScale(image, faceDetections);         
        int index = inputFileName.indexOf(".");
        String prefix = inputFileName.substring(0, index);
        String suffix = inputFileName.substring(index);        
        int count = 1;
        for (Rect rect : faceDetections.toArray()) {            
            Rect rectCrop = null;
            Imgproc.rectangle(image, new Point(rect.x - PADDING, rect.y - PADDING),new Point(rect.x + rect.width + PADDING, rect.y + rect.height + PADDING),new Scalar(0, 255, 0), 1);                                                                      
            rectCrop = new Rect(rect.x- PADDING, rect.y- PADDING, rect.width + PADDING, rect.height + PADDING);
            Mat image_roi = new Mat(image, rectCrop);
            Imgcodecs.imwrite(prefix + "_detectedFace" + count + suffix, image_roi);   
            count++;
        }                 
        String outputFileName = prefix + "_detected" + suffix;
        Imgcodecs.imwrite(outputFileName, image);
}
edit retag flag offensive close merge delete

Comments

can you take another look at your question ? how would we know, what you tried, and what went wrong ?

berak gravatar imageberak ( 2019-02-25 12:55:46 -0500 )edit

I edited my original post to add my code. Thanks for any help

ray4 gravatar imageray4 ( 2019-02-25 13:50:08 -0500 )edit
1

there are params to tweak, like minNeighbours, min/maxSize()

berak gravatar imageberak ( 2019-02-27 02:30:21 -0500 )edit