Alejandro Sanchez
Alejandro Sanchez

Reputation: 89

Opencv - Detecting eye pupil (middle)

I'm dealing with a problem trying to identify the eye pupil's middle.

Right now I'm developing an Opencv program to detect the pupil, I already achieve this goal but I need to improve the accuracy. So I gonna show the piece of code for detecting the pupil and an image with the result.

def get_irises_location(self, frame_gray):
    self.eye_cascade = cv2.CascadeClassifier(join('haar', 'haarcascade_eye.xml'))
    eyes = self.eye_cascade.detectMultiScale(frame_gray, 1.3, 10)  # if not empty - eyes detected
    irises = []

    for (ex, ey, ew, eh) in eyes:
        iris_w = int(ex + float(ew / 2))
        iris_h = int(ey + float(eh / 2))
        irises.append([numpy.float32(iris_w), numpy.float32(iris_h)])

    return numpy.array(irises)

pupil detector

As you can see, I already detect the eye pupil, but I need to hit just in the middle of it.

Upvotes: 2

Views: 6100

Answers (3)

galmeriol
galmeriol

Reputation: 461

If you are going to work with NIR images than i will suggest you to look at integrodifferential operator for detecting iris presented in following paper;

https://www.cl.cam.ac.uk/~jgd1000/csvt.pdf

I think implementation of this approach would work in color images with little tweaks.

Upvotes: 1

Well, some years ago I realized a very similar project.

We used one little trick. We used IR light (infra-red) instead of visible light. In IR with no dependence on real color of iris, iris will be light-gray, and the pupil will be absolutely black. This will significantly simplify your task.

I also can give you a link to Open eyes project paper

"Open eyes" - is open source project of eyetracker where software and hardware documentation are absolutely open and free.

I hope it will help

Upvotes: 3

Akshay Bahadur
Akshay Bahadur

Reputation: 517

As I can see, you are using Haar Classifier for detecting eye. Haar classifiers are not good for starting out however, it is not very accurate. Maybe you could add something like this :

 for (ex, ey, ew, eh) in eyes:
        iris_w = int((ex+epsilon) + float((ew / 2)+epsilon))
        iris_h = int((ey+epsilon) + float((eh / 2)+epsilon))
        irises.append([numpy.float32(iris_w), numpy.float32(iris_h)])

Here, epsilon is an adjustment factor which moves the green dot to the middle. However, this will not work.

The better approach would be to train a model to detect facial landmarks which can detect the centre of the pupil even when the pupil moves away.

See here : https://github.com/akshaybahadur21/Drowsiness_Detection

Upvotes: 2

Related Questions