title: opencv face recognition, get coordinates of "bounding box" around image
body: <p>today I was trying a project with opencv in java and I was following <a href="https://blog.openshift.com/day-12-opencv-face-detection-for-java-developers/" rel="nofollow">this</a> code. I modified it to work with opencv 3.0.0. Basically I'm trying to take a bunch of images from a folder and crop the pictures where the face recognition finds the face. So the problem is I can't seem to get the coordinates of the "bounding box" that goes around the image  (<a href="http://docs.opencv.org/3.0-beta/_images/faceDetection.png" rel="nofollow">bounding box</a>). I want to crop the image to the box, does anyone know what I am talking about or what to do?</p>
  
  <p>Any help is appreciated! :) I am a (<em>very</em>) beginner programmer. Thank you!</p>
  
  <pre><code>import java.io.File;
  import java.io.IOException;
  import org.opencv.core.Core;
  import org.opencv.core.Mat;
  import org.opencv.core.MatOfRect;
  import org.opencv.core.Point;
  import org.opencv.core.Rect;
  import org.opencv.core.Scalar;
  import org.opencv.imgcodecs.Imgcodecs;
  import org.opencv.imgproc.Imgproc;
  import org.opencv.objdetect.CascadeClassifier;
  
  public class hello {
      public static void main(String[] args) throws IOException {
      System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
      System.out.println("\nRunning FaceDetector");
  
      CascadeClassifier faceDetector = new CascadeClassifier("C:/Users/Family/workspace/detect face/haarcascade_frontalface_alt.xml");
  
      File folder = new File("C:\\Users\\Family\\Downloads\\Photos");
      File[] listOfFiles = folder.listFiles();
  
      for (int j = 0; j &lt; listOfFiles.length; j++) {
          System.out.println(listOfFiles[j]);
      }
  
      for (int i = 0; i &lt; listOfFiles.length-1; i++){
          String picname = listOfFiles[i].toString();
  
          System.out.println("reading: " + listOfFiles[i]);
  
          Mat image = Imgcodecs.imread(picname);
  
          MatOfRect faceDetections = new MatOfRect();
          faceDetector.detectMultiScale(image, faceDetections);
  
          System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));
  
  
          for (Rect rect : faceDetections.toArray()) {
              Imgproc.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 = "monkey.png";
          System.out.println(String.format("Writing %s", filename));
          Imgcodecs.imwrite(filename, image);
  
      }
  }
  </code></pre>
  
  <p>}</p>