Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Some faces not detection

Hello members, This is my first question on this forum. Just, I started project on openCV. By using java file I am uploading image after uploading it detect faces and make rectangle to face. In my image there are 14 faces and its detecting 12 faces.

this is code

      String file ="C:/EXAMPLES/OpenCV/group12.jpg";
      Mat src = Imgcodecs.imread(file);

      // Instantiating the CascadeClassifier
      String xmlFile = "C:/EXAMPLES/facedetect/lbpcascade_frontalface.xml";
      CascadeClassifier classifier = new CascadeClassifier(xmlFile);

      // Detecting the face in the snap
      MatOfRect faceDetections = new MatOfRect();
      classifier.detectMultiScale(src, faceDetections);
      System.out.println(String.format("Detected %s faces", 
         faceDetections.toArray().length));

      // Drawing boxes
      for (Rect rect : faceDetections.toArray()) {
         Imgproc.rectangle(
            src,                                               // where to draw the box
            new Point(rect.x, rect.y),                            // bottom left
            new Point(rect.x + rect.width, rect.y + rect.height), // top right
            new Scalar(0, 0, 255),
            3                                                     // RGB colour
         ); 
      }

image description