how to detect eye pupil circularly in opencv
Asked Answered
O

1

8

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;
  }
Oud answered 12/12, 2013 at 4:52 Comment(4)
why r u detecting pupil, i think you are talking about eye ballAntagonism
@Antagonism if you have eye ball code, can u kindly share that code.Oud
if i give you the code. then where is you part? :PAntagonism
@Antagonism you are not helping person thanksOud
E
3

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)

Endoparasite answered 12/12, 2013 at 9:50 Comment(2)
thank you very much. i understand what you said but can you please share some code example about edge detection, how can i detect the edge of eye pupil ?Oud
I don't have relevant code available. but open cv has some algorithms implemented.Endoparasite

© 2022 - 2024 — McMap. All rights reserved.