Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to detect eye pupil circularly in opencv

I am working on opencv in android and i want to change eye pupil color through Hue channel and i achieve this already but the problem is that the region i detected is in rectangle but i want this region circular as eye pupil is circular region. kindly help how i achieve this.

private Mat  get_template(CascadeClassifier clasificator, Rect area,int size){
    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;
        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));
        mROI = mGray.submat(eye_only_rectangle);
        Mat vyrez = mRgba.submat(eye_only_rectangle);
        Core.MinMaxLocResult mmG = Core.minMaxLoc(mROI);

        Core.circle(vyrez, mmG.minLoc,2, new Scalar(255, 255, 255, 255),2);
        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);
        Core.rectangle(mRgba,eye_template.tl(),eye_template.br(),new Scalar(255, 0, 0, 255), 2);
        template = (mGray.submat(eye_template)).clone();
        return template;
    }
     return template;
  }
like image 995
Saad Bilal Avatar asked Dec 12 '13 04:12

Saad Bilal


1 Answers

Some potential solutions:

  • the simplest, although it might not be very robust is to calculate the inscribed circle (the circle bound by the rectangle) and change it's color - if your pupil detection is very accurate this solution may work fine.

  • a more robust solution would be to detect the area of the pupil based on color or gradient (edge detection)

like image 139
Ophir Yoktan Avatar answered Oct 05 '22 01:10

Ophir Yoktan