haar cascade for eye ball in opencv android

Viewed 2432

I am working on opencv eye detection project and i have sucessfully detect rectangular region of both eyes through the help of haar cascade for boths eyes. now i want to detect the eye balls from both eyes, the problem is that i have no haar cascade for eye ball tracking. kindly help me if anyone of you have this xml and suggest other solution. here is my code of eye detection

    private Mat  get_template(CascadeClassifier clasificator, Rect area,int size)
{
        Mat eye = new Mat();
        Mat template = new Mat();
        Mat mROI = mGray.submat(area);
        MatOfRect eyes = new MatOfRect();
        Point iris = new Point();
        Rect eye_template = new Rect();
        clasificator.detectMultiScale(mROI, eyes, 1.15, 2, Objdetect.CASCADE_FIND_BIGGEST_OBJECT|Objdetect.CASCADE_SCALE_IMAGE, new Size(30,30), new Size());
    Rect[] eyesArray = eyes.toArray();

    for (int i = 0; i < eyesArray.length; i++)

    {

        Rect e = eyesArray[i];

        e.x = area.x + e.x;
        e.y = area.y + e.y;

        Core.rectangle(mROI, e.tl(), e.br(), new Scalar(25, 50, 0, 255));

        Rect eye_only_rectangle = new Rect((int)e.tl().x,   (int)( e.tl().y + e.height*0.4),   (int)e.width,   (int)(e.height*0.6));
        //reduce ROI
        mROI = mGray.submat(eye_only_rectangle);
        Mat vyrez = mRgba.submat(eye_only_rectangle);
        Core.MinMaxLocResult mmG = Core.minMaxLoc(mROI);
        //Draw pink circle on eyeball
        int radius = vyrez.height()/2; 
   //   Core.circle(vyrez, mmG.minLoc, 2, new Scalar(0, 255, 0, 1), radius);
        //Core.circle(vyrez, mmG.minLoc,2, new Scalar(255, 0, 255),1);
        iris.x = mmG.minLoc.x + eye_only_rectangle.x;
        iris.y = mmG.minLoc.y + eye_only_rectangle.y;
        eye_template = new Rect((int)iris.x-size/2,(int)iris.y-size/2 ,size,size);
        //draw red rectangle around eyeball 
        //Core.rectangle(mRgba,eye_template.tl(),eye_template.br(),new Scalar(255, 0, 0, 255), 2);
        eye = (mRgba.submat(eye_only_rectangle));
        template = (mGray.submat(eye_template)).clone();
        //return template;

        Mat eyeball_HSV = new Mat();
        Mat dest = new Mat();       
        //Mat eye = new Mat();

        //eye = mRgba.submat(eye_only_rectangle);

        List<Mat> hsv_channel = new ArrayList<Mat>();
         //convert image to HSV 
           Imgproc.cvtColor(eye, eyeball_HSV, Imgproc.COLOR_RGB2HSV, 0);

          // get HSV channel 
        //hsv_channel[0] is hue
        //hsv_channel[1] is saturation
        //hsv_channel[2] is visibility
        Core.split(eyeball_HSV, hsv_channel);

        try
        {
             hsv_channel.get(0).setTo(new Scalar(145));

             Log.v(TAG, "Got the Channel!");
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
            Log.v(TAG, "Didn't get any channel");
        }

        Core.merge(hsv_channel, eyeball_HSV);

        Imgproc.cvtColor(eyeball_HSV, dest, Imgproc.COLOR_HSV2RGB);
        Imgproc.cvtColor(dest, eye, Imgproc.COLOR_RGB2RGBA);    


    }

     return eye;
  }`enter code here`  
1 Answers
Related