我正在尝试评估一个人闭嘴时嘴唇是否移动过多(以得出其正在咀嚼的结论)。
嘴巴闭合部分没有任何问题,但是当我尝试通过标志评估嘴唇运动时(
dlib
),嘴巴的最后一个标志似乎有问题。
受到嘴巴示例的启发(https://github.com/mauckc/mouth-open/blob/master/detect_open_mouth.py#L17),我编写了以下函数:
def lips_aspect_ratio(shape):
# grab the indexes of the facial landmarks for the lip
(mStart, mEnd) = (61, 68)
lip = shape[mStart:mEnd]
print(len(lip))
# compute the euclidean distances between the two sets of
# vertical lip landmarks (x, y)-coordinates
# to reach landmark 68 I need to get lib[7] not lip[6] (while I get lip[7] I get IndexOutOfBoundError)
A = dist.euclidean(lip[1], lip[6]) # 62, 68
B = dist.euclidean(lip[3], lip[5]) # 64, 66
# compute the euclidean distance between the horizontal
# lip landmark (x, y)-coordinates
C = dist.euclidean(lip[0], lip[4]) # 61, 65
# compute the lip aspect ratio
mar = (A + B) / (2.0 * C)
# return the lip aspect ratio
return mar
嘴唇的标志是
(61, 68)
,当我将嘴唇提取为lip = shape[61:68]
并尝试访问最后一个标志为lip[7]
时,我收到以下错误:
IndexError: index 7 is out of bounds for axis 0 with size 7
这是为什么呢?以及如何获得嘴唇/脸部的最后一个标志 否则如何定义嘴唇的纵横比来断定它们正在显着移动?
lip = shape[61:68]
切片不包括结束元素。所以你得到了 7 个元素:61,62,63,64,65,66,67。
len(lip) == 7
证实了这一点。
如果嘴唇形状确实有 8 个点,并且它们包含元素 68,则切片应该是:
lip = shape[61:69]