Ask Your Question

moods's profile - activity

2015-01-17 11:51:32 -0600 commented answer Face Detection through a webcam in java

thanks @orochi. the program is now working fine and i can detect face and eyes from webcam in real-time. Next thing i wanna do is detect the iris and estimate the gaze. Have you ever done iris recognition?

2015-01-08 08:49:24 -0600 commented answer Face Detection through a webcam in java

Woaaaa @orochi. It finally detects face and my left eye only. Dont know why it cant detect both my eyes. And one more thing, how to track the face and eye in real time from webcam? I mean like track eye in video rather than a picture. Thank you for your reply. I really appreciate it.

2015-01-07 11:43:29 -0600 commented answer Face Detection through a webcam in java

@orochi I am getting the error Assertion failed and I think it is because I am getting an empty Mat at this line:

Mat frame = new Mat(); capture.retrieve(frame);

Do you know how to fix this? THanks

2015-01-07 01:18:40 -0600 asked a question Opencv error: Bad Flag. Unrecognised or unsupported array type.

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;

public class Eye {

/** Global variables */
 String face_cascade_name = "D:/Program Files/opencv2410/sources/data/haarcascades/haarcascade_frontalface_alt.xml";
 String eyes_cascade_name = "D:/Program Files/opencv2410/sources/data/haarcascades/haarcascade_eye_tree_eyeglasses.xml";
 CascadeClassifier face_cascade = new CascadeClassifier();
 CascadeClassifier eyes_cascade = new CascadeClassifier();
 String window_name = "Capture - Face detection";


 public void detectAndDisplay(Mat frame)
 {
   Mat frame_gray = new Mat();
   MatOfRect faces = new MatOfRect();

   Rect[] facesArray = faces.toArray();

   if(frame.empty())
   {
       System.out.print("Error");
   }
   else
   {
   Imgproc.cvtColor(frame, frame_gray, Imgproc.COLOR_BGRA2GRAY);
   Imgproc.equalizeHist(frame_gray, frame_gray);
   }

   //-- Detect faces
   face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0, new Size(30, 30), new Size() );

   for (int i = 0; i < 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 < 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);
   VideoCapture capture;
   Mat frame = new Mat();
   Eye ey = new Eye();

   //-- 1. Load the cascades
   if (!ey.face_cascade.load(ey.face_cascade_name))
   {
       System.out.print("--(!)Error loading\n");
       return;
   }
   if (!ey.eyes_cascade.load(ey.eyes_cascade_name))
   {
       System.out.print("--(!)Error loading\n");
       return;
   }

   //-- 2. Read the video stream
   capture = new VideoCapture(0);
   if(!capture.isOpened())
   {
       System.out.println("Did not connect to camera.");
   }
   else
   {
       capture.retrieve(frame);
       ey.detectAndDisplay(frame);
       capture.release();
   }
   }

}

Im getting the error: OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, 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 in function cvGetMat ] at org.opencv.objdetect.CascadeClassifier.detectMultiScale_0(Native Method) at org.opencv.objdetect.CascadeClassifier.detectMultiScale(CascadeClassifier.java:100) at Eye.detectAndDisplay(Eye.java:43) at Eye.main(Eye.java:100)

2015-01-07 01:18:40 -0600 commented answer Face Detection through a webcam in java

Hi, when i run the code i get this error OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, 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 in function cvGetMat ]

can anyone explain why?