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 :
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.
