title: Face Detection using a webcam interface in Java in Windows
body: <p>I am new to OpenCV, and working on a face detection project. I wanted to create a webcam interface for face detection and I referred to the tutorial: <a href="http://answers.opencv.org/question/12978/face-detection-through-a-webcam-in-java/" rel="nofollow">here</a>
  I made following changes to the code( modification to the CascadeClassifier position and HaarCascade file path only):</p>
  
  <pre><code>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.Size;
  import org.opencv.core.Scalar;
  import org.opencv.highgui.Highgui;
  import org.opencv.highgui.VideoCapture;
  import org.opencv.imgproc.Imgproc;
  import org.opencv.objdetect.CascadeClassifier;
  import static com.googlecode.javacv.cpp.opencv_core.cvFlip;
  
  public class detedctAndDisplay {
      /** Global variables */
  
      private static String face_cascade_name = "haarcascade_frontalface_alt.xml";
      private static String eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
  
      private static CascadeClassifier face_cascade;
      private static CascadeClassifier eyes_cascade;
      private static String window_name = "Capture - Face detection";
  
      public detedctAndDisplay(){
          face_cascade = new CascadeClassifier("C:\\Users\\Admin\\Desktop\\face detection\\FaceDetection\\src\\haarcascade_frontalface_alt.xml"); 
          eyes_cascade = new CascadeClassifier("C:\\Users\\Admin\\Desktop\\face detection\\FaceDetection\\src\\"+eyes_cascade_name);
      }
  
      public static void detectAndDisplay(Mat frame)
      {
          CascadeClassifier face_cascade= new CascadeClassifier("C:\\Users\\Admin\\Desktop\\face detection\\FaceDetection\\src\\haarcascade_frontalface_alt.xml");
  
          Mat frame_gray = new Mat();
          MatOfRect faces = new MatOfRect();
  
          Rect[] facesArray = faces.toArray();
  
          // Imgproc.cvtColor(frame, frame_gray, Imgproc.COLOR_BGRA2GRAY);
          Imgproc.equalizeHist(frame_gray, frame_gray);
  
          //-- Detect faces
  
  
          face_cascade.detectMultiScale(frame_gray,faces );
  
  
          for (int i = 0; i &lt; facesArray.length; i++)
          {
  
              Point center = new Point(facesArray[i].x + facesArray[i].width * 0.5, facesArray[i].y + facesArray[i].height * 0.5);
  
              Core.ellipse(frame, center, new Size(facesArray[i].width * 0.5, facesArray[i].height * 0.5), 0, 0, 360, new Scalar(255, 0, 255), 4, 8, 0);
  
              Mat faceROI = frame_gray.submat(facesArray[i]);
  
              MatOfRect eyes = new MatOfRect();
  
              Rect[] eyesArray = eyes.toArray();
  
              //-- In each face, detect eyes
              eyes_cascade.detectMultiScale(faceROI, eyes, 1.1, 2, 0,new Size(30, 30), new Size());
  
              for (int j = 0; j &lt; eyesArray.length; j++)
              {
  
                  Point center1 = new Point(facesArray[i].x + eyesArray[i].x + eyesArray[i].width * 0.5,   facesArray[i].y + eyesArray[i].y + eyesArray[i].height * 0.5);
                  int radius = (int) Math.round((eyesArray[i].width + eyesArray[i].height) * 0.25);
                  Core.circle(frame, center1, radius, new Scalar(255, 0, 0), 4, 8, 0);
  
              }
          }
          //-- Show what you got
          Highgui.imwrite(window_name, frame);
      }
  
      /**
      * @param args
      */
      public static void main(String[] args)
      {
          System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
          //face_cascade = new CascadeClassifier("C:\\Users\\Admin\\Desktop\\face detection\\FaceDetection\\src\\haarcascade_frontalface_alt.xml");
          CascadeClassifier face_cascade1 = new CascadeClassifier("C:\\Users\\Admin\\Desktop\\face detection\\FaceDetection\\src\\haarcascade_frontalface_alt.xml"); 
          //eyes_cascade = new CascadeClassifier("C:\\Users\\Admin\\Desktop\\face detection\\FaceDetection\\src\\"+eyes_cascade_name);
          VideoCapture capture;
          Mat frame = new Mat();
  
  
          capture = new VideoCapture(0);
  
          if(!capture.isOpened())
          {
              System.out.println("Did not connect to camera.");
          }
          else
          {
  
              capture.retrieve(frame);
  
              detectAndDisplay(frame);
  
              capture.release();
  
          }
      }
  
  }
  </code></pre>
  
  <p>I am getting following error:</p>
  
  <pre><code>OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type
  in unknown function, file ..\..\..\..\opencv\modules\core\src\array.cpp, line 2482
  Exception in thread "main" CvException [org.opencv.core.CvException:    
  cv::Exception: ..\..\..\..\opencv\modules\core\src\array.cpp:2482: error: (-206) Unrecognized or 
  unsupported array type
  ]
  at org.opencv.objdetect.CascadeClassifier.detectMultiScale_1(Native Method)
  at org.opencv.objdetect.CascadeClassifier.detectMultiScale(CascadeClassifier.java:127)
  at detedctAndDisplay.detectAndDisplay(detedctAndDisplay.java:55)
  at detedctAndDisplay.main(detedctAndDisplay.java:125)
  </code></pre>
  
  <p>I am unable to resolve the error.
  Also, please tell which jar to import so that cvtColor could be used?
  Thanks!</p>