python - 我的Python代码中的问题是检测到眨眼次数过多。 (使用眼睛纵横比方法)

标签 python opencv

我正在尝试使用 openCV 和 python 检测视频中的人眼眨眼。

所以,我在github上找到了一个非常有效的示例代码,我正在重构它。

我的代码是基于 EAR(Eye-Aspect-Ratio)方法实现的,该方法由 Tereza Soukupova 和 Jan Cech 于 2016 年发明。

eye_aspect_ratio()取眼睛周围的六个点,计算水平轴和垂直轴的绝对面积。

这是眼睛纵横比的方法:

enter image description here

这是我的代码:

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)

但是,我的代码中存在一个问题,即检测到的眨眼次数过多。

我认为,我的代码错误地检测到它不是眨眼(例如微笑的眼睛或眨眼)

我有什么遗漏的地方吗?

请帮助我。

最佳答案

一般来说,双眼同时眨眼。

因此,您应该通过使用 leftEARrightEAR 的成本来使用将眼睛比率除以一半的总和和除以的值

我认为使用这种方法可以解决一些问题。

您可以尝试以下代码:

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/

相关文章:

python - 如何知道调用 shell 目录的路径并在我的 python 可执行文件中使用它

python - python 2.7.x 中的继承

python - 如何使用非自由模块为 Python 构建 OpenCV 3.0.0?

python - pytesseract不适用于数字图像

c++ - 我如何使用包含 vector<Mat> 的结构 vector

java - 我在 android 上通过 bitmapToMat 得到了 CvException

python - 将 Python PIL 代码转换为 Python OpenCV

python - 引用numpy结构化数组中的字段与整个数组的大小相同

python - 使用 pymongo,如何找到所有文档,使得每个文档中的嵌入列表包含大于 X 个元素?

Python - Pandas 使用 np.where 创建列以获取多个不同的值