Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

real time face tracking

Hi guys, I'm very vey new to opencv. i'm trying to make a Java program that can detect my face through a webcam. i don't know which library i should import and i don't know how to make it able to detect my webcam. I've been trying to find a tutorial regarding my problem, but i cant find it. any hints i really appreciate it.

real time face trackingtracking java

Hi guys, I'm very vey new to opencv. i'm trying to make a Java program that can detect my face through a webcam. i don't know which library i should import and i don't know how to make it able to detect my webcam. I've been trying to find a tutorial regarding my problem, but i cant find it. any hints i really appreciate it.

real time face tracking java

Hi guys, I'm very vey new to opencv. i'm trying to make a Java program that can detect my face through a webcam. i don't know which library i should import and i don't know how to make it able to detect my webcam. I've been trying to find a tutorial regarding my problem, but i cant find it. any hints i really appreciate it.

real time face tracking java

Hi guys, I'm very vey new to opencv. i'm trying to make a Java program that can detect my face through a webcam. i don't know which library i should import and i don't know how to make it able to detect my webcam. I've been trying to find a tutorial regarding my problem, but i cant find it. any hints hints? i really appreciate it.

real time face tracking java

Hi guys, I'm very vey new to opencv. i'm trying to make a Java program that can detect my face through a webcam. i don't know which library i should import and i don't know how to make it able to detect my webcam. I've been trying Based on this tutorial i try to find write my java code for detecting face through a tutorial regarding my problem, webcam, but i cant find it. any hints? got so many errors, can someone tell me why the error occur? I'm new in opencv and java.

import org.opencv.core.Mat;
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.imgproc.Imgproc;
import org.opencv.objdetect.CascadeClassifier;
import java.util.Vector;

import java.io.*;
import java.lang.Enum;

/**
 * @author Lycosa
 *
 */
public class detedctAndDisplay {



    /** Global variables */
     private static final int CV_HAAR_SCALE_IMAGE = 0;
     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 = new CascadeClassifier();
     private static CascadeClassifier eyes_cascade = new CascadeClassifier();
     private static String window_name = "Capture - Face detection";


     private static void detectAndDisplay(Mat frame)
     {
       Vector<Rect> faces = new Vector<Rect>();
       Mat frame_gray = new Mat();

       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|CV_HAAR_SCALE_IMAGE, new Size(30, 30) )

       for (int i really appreciate it.

= 0; i < faces.size(); i++) { Point center = new Point(faces.get(i).x + faces.get(i).width * 0.5, faces.get(i).y + faces.get(i).height * 0.5); ellipse(frame, center, new Size(faces.get(i).width * 0.5, faces.get(i).height * 0.5), 0, 0, 360, new Scalar(255, 0, 255), 4, 8, 0); Mat faceROI = frame_gray(faces.get(i)); Vector<Rect> eyes = new Vector<Rect>(); //-- In each face, detect eyes eyes_cascade.detectMultiScale(faceROI, eyes, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, new Size(30, 30)); for (int j = 0; j < eyes.size(); j++) { Point center1 = new Point(faces.get(i).x + eyes.get(j).x + eyes.get(j).width * 0.5, faces.get(i).y + eyes.get(j).y + eyes.get(j).height * 0.5); int radius = cvRound((eyes.get(j).width + eyes.get(j).height) * 0.25); circle(frame, center1, radius, new Scalar(255, 0, 0), 4, 8, 0); } } //-- Show what you got imshow(window_name, frame); } /** * @param args */ private static void Main(String[] args) { CvCapture capture; Mat frame = new Mat(); //-- 1. Load the cascades if (!face_cascade.load(face_cascade_name)) { System.out.print("--(!)Error loading\n"); return -1; }; if (!eyes_cascade.load(eyes_cascade_name)) { System.out.print("--(!)Error loading\n"); return -1; }; //-- 2. Read the video stream capture = cvCaptureFromCAM(-1); if (capture != null) { while (true) { frame = cvQueryFrame(capture); //-- 3. Apply the classifier to the frame if (!frame.empty()) { detectAndDisplay(frame); } else { System.out.print(" --(!) No captured frame -- Break!"); break; } int c = waitKey(10); if ((byte)c == 'c') { break; } } } }}
click to hide/show revision 6
already update my code, now no error but eyes detection not working

real time face tracking java

Hi guys, I'm very vey new to opencv. i'm trying to make a Java program that can detect my face through a webcam. i don't know which library i should import and i don't know how to make it able to detect my webcam. Based on this tutorial i try to write my java code for detecting face through a webcam, but i got so many errors, can someone tell me why the error occur? I'm new in opencv and java.

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.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 java.util.Vector; import java.io.*; import java.lang.Enum; /** * @author Lycosa * */ org.opencv.objdetect.CascadeClassifier;

public class detedctAndDisplay { /** Global variables */ private CamCapture {

/**
 * @param args
 */ 

public static final int CV_HAAR_SCALE_IMAGE = 0;
     private static void main(String[] args) {

    //load opencv native library
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

    String face_cascade_name = "haarcascade_frontalface_alt.xml";
     private static String eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
     private static CascadeClassifier face_cascade = new CascadeClassifier();
     private static CascadeClassifier eyes_cascade = new CascadeClassifier();
     private static String window_name = "Capture - Face detection";


     private static void detectAndDisplay(Mat frame)
     {
       Vector<Rect> faces = new Vector<Rect>();
   detection.jpg";

    System.out.println("capture through camera "+Core.VERSION);


    //load the face xml cascade
    if(!face_cascade.load(face_cascade_name))
    {
        System.out.println("Error loading face cascade");
    }
    else
    {
        System.out.println("Success loading face cascade");
    }

    //load the eyes xml cascade
    if(!eyes_cascade.load(eyes_cascade_name))
    {
        System.out.println("Error loading eyes cascade");
    }
    else
    {
        System.out.println("Success loading eyes cascade");
    }

    //detect default camera
    VideoCapture capture = new VideoCapture(0);

    if(!capture.isOpened())
    {
        System.out.println("Did not connected to camera.");
    }
    else
    {
        System.out.println("Conected to camera: "+capture.toString());
    }

    //create new Mat image
    Mat frame = new Mat();
    capture.retrieve(frame);

    Mat frame_gray = new Mat();
     Imgproc.cvtColor(frame, frame_gray, Imgproc.COLOR_BGRA2GRAY);
     Imgproc.equalizeHist(frame_gray, frame_gray);

       //-- Detect faces
       face_cascade.detectMultiScale( frame_gray, 
    MatOfRect faces = new MatOfRect();

    face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, 0, new Size(30, 30) )

       for (int i = 0; i < faces.size(); 30), new Size() );


    Rect[] facesArray = faces.toArray();

    for(int i=0; i<facesArray.length; i++)
       {
 {
        Point center = new Point(faces.get(i).x Point(facesArray[i].x + faces.get(i).width facesArray[i].width * 0.5, faces.get(i).y facesArray[i].y + faces.get(i).height facesArray[i].height * 0.5);
         ellipse(frame, Core.ellipse(frame, center, new Size(faces.get(i).width Size(facesArray[i].width * 0.5, faces.get(i).height facesArray[i].height * 0.5), 0, 0, 360, new Scalar(255, 0, 255), 4, 8, 0);

         Mat faceROI = frame_gray(faces.get(i));
         Vector<Rect> frame_gray.submat(facesArray[i]);
         MatOfRect eyes = new Vector<Rect>();
MatOfRect();

         Rect[] eyesArray = eyes.toArray();

         //-- In each face, detect eyes
         eyes_cascade.detectMultiScale(faceROI, eyes, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, new 0,new Size(30, 30));
30), new Size());

         for (int j = 0; j < eyes.size(); eyesArray.length; j++)
         {
            Point center1 = new Point(faces.get(i).x Point(facesArray[i].x + eyes.get(j).x eyesArray[i].x + eyes.get(j).width eyesArray[i].width * 0.5, faces.get(i).y facesArray[i].y + eyes.get(j).y eyesArray[i].y + eyes.get(j).height eyesArray[i].height * 0.5);
            int radius = cvRound((eyes.get(j).width (int) Math.round((eyesArray[i].width + eyes.get(j).height) eyesArray[i].height) * 0.25);
            circle(frame, Core.circle(frame, center1, radius, new Scalar(255, 0, 0), 4, 8, 0);
         }
       }
       //-- Show what you got
       imshow(window_name, }

    Highgui.imwrite(window_name, frame);
     }

    /**
     * @param args
     */
     private static void Main(String[] args)
     {
       CvCapture capture;
       Mat frame = new Mat();

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

       //-- 2. Read the video stream
       capture = cvCaptureFromCAM(-1);
       if (capture != null)
       {
         while (true)
         {
       frame = cvQueryFrame(capture);

       //-- 3. Apply the classifier to the frame
           if (!frame.empty())
           {
               detectAndDisplay(frame);
           }
           else
           {
               System.out.print(" --(!) No captured frame -- Break!");
               break;
           }

           int c = waitKey(10);
           if ((byte)c == 'c')
           {
               break;
           }
         }
       }


}}
capture.release();

}

}

real time face tracking java

Hi guys, I'm very vey new to opencv. i'm trying to make a Java program that can detect my face through a webcam. i don't know which library i should import and i don't know how to make it able to detect my webcam. Based on this tutorial i try to write my java code for detecting face through a webcam, but i got so many errors, can someone tell me why the error occur? I'm new in opencv and java.

 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.core.Size; import org.opencv.highgui.Highgui; import org.opencv.highgui.VideoCapture; import org.opencv.imgproc.Imgproc; import org.opencv.objdetect.CascadeClassifier;

org.opencv.objdetect.CascadeClassifier; public class CamCapture {

{

    /**
  * @param args
  */ 

 public static void main(String[] args) {

     //load opencv native library
     System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

     String face_cascade_name = "haarcascade_frontalface_alt.xml";
     String eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
     CascadeClassifier face_cascade = new CascadeClassifier();
     CascadeClassifier eyes_cascade = new CascadeClassifier();
     String window_name = "Capture - Face detection.jpg";

     System.out.println("capture through camera "+Core.VERSION);


     //load the face xml cascade
     if(!face_cascade.load(face_cascade_name))
     {
         System.out.println("Error loading face cascade");
     }
     else
     {
         System.out.println("Success loading face cascade");
     }

     //load the eyes xml cascade
     if(!eyes_cascade.load(eyes_cascade_name))
     {
         System.out.println("Error loading eyes cascade");
     }
     else
     {
         System.out.println("Success loading eyes cascade");
     }

     //detect default camera
     VideoCapture capture = new VideoCapture(0);

     if(!capture.isOpened())
     {
         System.out.println("Did not connected to camera.");
     }
     else
     {
         System.out.println("Conected to camera: "+capture.toString());
     }

     //create new Mat image
     Mat frame = new Mat();
     capture.retrieve(frame);

     Mat frame_gray = new Mat();
     Imgproc.cvtColor(frame, frame_gray, Imgproc.COLOR_BGRA2GRAY);
     Imgproc.equalizeHist(frame_gray, frame_gray);


     MatOfRect faces = new MatOfRect();

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


     Rect[] facesArray = faces.toArray();

     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);
          }
     }

     Highgui.imwrite(window_name, frame);
     capture.release();

 }

 }
click to hide/show revision 8
code working perfectly without error

real time face tracking java

Hi guys, I'm very vey new to opencv. i'm trying to make a Java program that can detect my face through a webcam. i don't know which library i should import and i don't know how to make it able to detect my webcam. Based on this tutorial i try to write my java code for detecting face through a webcam, but i got so many errors, can someone tell me why the error occur? I'm new in opencv and java.

  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.core.Size;
import org.opencv.highgui.Highgui;
import org.opencv.highgui.VideoCapture;
import org.opencv.imgproc.Imgproc;
import org.opencv.objdetect.CascadeClassifier;

public class CamCapture {

    /**
     * @param args
     */ 

    public static void main(String[] args) {

        //load opencv native library
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

        String face_cascade_name = "haarcascade_frontalface_alt.xml";
        String eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
        CascadeClassifier face_cascade = new CascadeClassifier();
        CascadeClassifier eyes_cascade = new CascadeClassifier();
        String window_name = "Capture - Face detection.jpg";

        System.out.println("capture through camera "+Core.VERSION);


        //load the face xml cascade
        if(!face_cascade.load(face_cascade_name))
        {
            System.out.println("Error loading face cascade");
        }
        else
        {
            System.out.println("Success loading face cascade");
        }

        //load the eyes xml cascade
        if(!eyes_cascade.load(eyes_cascade_name))
        {
            System.out.println("Error loading eyes cascade");
        }
        else
        {
            System.out.println("Success loading eyes cascade");
        }

        //detect default camera
        VideoCapture capture = new VideoCapture(0);

        if(!capture.isOpened())
        {
            System.out.println("Did not connected to camera.");
        }
        else
        {
            System.out.println("Conected to camera: "+capture.toString());
        }

        //create new Mat image
        Mat frame = new Mat();
        capture.retrieve(frame);

        Mat frame_gray = new Mat();
        Imgproc.cvtColor(frame, frame_gray, Imgproc.COLOR_BGRA2GRAY);
        Imgproc.equalizeHist(frame_gray, frame_gray);


        MatOfRect faces = new MatOfRect();

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


        Rect[] facesArray = faces.toArray();

        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());
Size(30,30), new Size());            

             Rect[] eyesArray = eyes.toArray();

             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);
             }
        }

        Highgui.imwrite(window_name, frame);
        capture.release();

     }

 }