problem in my python code that eye blinks are too many detected. (using Eye-Aspect-Ratio method)

Viewed 121

I am trying to detect human eye blinking in video using openCV and python.

So, I found a very effective example code in github, and I am refactoring it.

My code was implemented based on EAR(Eye-Aspect-Ratio) method, Invented by Tereza Soukupova and Jan Cech in 2016.

eye_aspect_ratio() takes six points around the eyes and calculates the absolute area of the horizontal axis and vertical axis.

This is figure of eye aspect ratio method :

enter image description here

this is my code:

def eye_aspect_ratio(eye):
    A = dist.euclidean(eye[1], eye[5])
    B = dist.euclidean(eye[2], eye[4])
    C = dist.euclidean(eye[0], eye[3])
    ear = (A + B) / (2.0 * C)
    return ear

# (...)
# face detection using face_cascade
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
for (x, y, w, h) in faces:
    cropped = frame[y - int(h / 8):y + h + int(h / 8), x - int(w / 8):x + w + int(w / 8)]
    rects = detector(cropped, 0)
    for rect in rects:
        shape = predictor(cropped, rect)
        shape = face_utils.shape_to_np(shape)

        leftEye = shape[lStart:lEnd]
        rightEye = shape[rStart:rEnd]
        
        leftEAR = eye_aspect_ratio(leftEye)
        rightEAR = eye_aspect_ratio(rightEye)

However, there is a problem in my code that eye blinks are too many detected.

I think, my code misdetects that it is not eye blinks (e.g. smiling eyes or winking)

Is there something point I missed?

Please help me.

1 Answers

In general, eye blinks occur simultaneously in both eyes.

Thus, you should use the value which sums and divides in half the eye’s ratio through using the cost of the leftEAR and rightEAR

I think using this method will solve some of the problems.

You can try this code:

leftEAR = eye_aspect_ratio(leftEye)
rightEAR = eye_aspect_ratio(rightEye)

# use this value
EAR = (leftEAR + rightEAR) / 2.0 

Finally, use a value less than 0.3 when comparing the EAR to the threshold

Thank you. good luck.

Related