我正在尝试使用 openCV 和 python 检测视频中的人眼眨眼。
所以,我在github上找到了一个非常有效的示例代码,我正在重构它。
我的代码是基于 EAR(Eye-Aspect-Ratio)方法实现的,该方法由 Tereza Soukupova 和 Jan Cech 于 2016 年发明。
eye_aspect_ratio()取眼睛周围的六个点,计算水平轴和垂直轴的绝对面积。
这是眼睛纵横比的方法:
这是我的代码:
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)
但是,我的代码中存在一个问题,即检测到的眨眼次数过多。
我认为,我的代码错误地检测到它不是眨眼(例如微笑的眼睛或眨眼)
我有什么遗漏的地方吗?
请帮助我。
最佳答案
一般来说,双眼同时眨眼。
因此,您应该通过使用 leftEAR
和 rightEAR
的成本来使用将眼睛比率除以一半的总和和除以的值
我认为使用这种方法可以解决一些问题。
您可以尝试以下代码:
leftEAR = eye_aspect_ratio(leftEye)
rightEAR = eye_aspect_ratio(rightEye)
# use this value
EAR = (leftEAR + rightEAR) / 2.0
最后,在将 EAR
与 阈值
进行比较时,使用小于 0.3
的值
谢谢。祝你好运。
关于python - 我的Python代码中的问题是检测到眨眼次数过多。 (使用眼睛纵横比方法),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65676833/