如何从 dlib 68 x- y 坐标测量面部标志中两点之间的距离

how to mesure the distance between 2 points in the facial landmarks from dlib 68 x- y-coordinates

我正在使用 python 代码工作,如果某些面部特征点(dlib 的特征点)之间的距离有条件,实际上如果点 1 和点 29 之间的距离除以点 17 和点 29 的距离在 1.1 和 .9 之间然后应该拍摄照片,这是地标图和我正在工作的代码

COUNTER = 0
TOTAL = 0


shape_predictor= "shape_predictor_68_face_landmarks.dat" #dace_landmark
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor(shape_predictor)


(mStart, mEnd) = face_utils.FACIAL_LANDMARKS_IDXS["mouth"]
(lStart, lEnd) = face_utils.FACIAL_LANDMARKS_IDXS["left_eye"]
(rStart, rEnd) = face_utils.FACIAL_LANDMARKS_IDXS["right_eye"]
(jStart,jEnd) = face_utils.FACIAL_LANDMARKS_IDXS["jaw"]
(reStart,reEnd) = face_utils.FACIAL_LANDMARKS_IDXS["right_eyebrow"]
(leStart,leEnd)= face_utils.FACIAL_LANDMARKS_IDXS["left_eyebrow"]
(nStart,nEnd)= face_utils.FACIAL_LANDMARKS_IDXS["nose"]
#video que vamos a procesar

print("[INFO] starting video stream thread...")
vs = VideoStream(src=0).start()
fileStream = False
time.sleep(1.0)

fps= FPS().start()
cv2.namedWindow("test")
while True:
    frame = vs.read()
    frame = imutils.resize(frame, width=450)
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
    rects = detector(gray, 0)
    for rect in rects:
        shape = predictor(gray, rect)
        shape = face_utils.shape_to_np(shape)
        mouth= shape[mStart:mEnd]
        left_eye= shape[lStart:lEnd]
        right_eye = shape[rStart:rEnd]
        jaw = shape[jStart:jEnd]
        right_eyebrow = shape[reStart:reEnd]
        left_eyebrow = shape[leStart:leEnd]
        nose = shape[nStart:nEnd]

        #here is where i need help
        l1= what do i need to put here?
        l2 = what do i need to put here?
        ratio = l1/l2

        mouthHull = cv2.convexHull(mouth)
        left_eyeHull = cv2.convexHull(left_eye)
        right_eyehHull = cv2.convexHull(right_eye)
        jawhHull = cv2.convexHull(jaw)
        right_eyebrowHull = cv2.convexHull(right_eyebrow)
        noseHull = cv2.convexHull(nose)
        left_eyebrowHull = cv2.convexHull(left_eyebrow)
        #print(shape)
        cv2.drawContours(frame, [mouthHull,left_eyeHull, right_eyehHull, jawhHull, right_eyebrowHull, noseHull, left_eyebrowHull], -1, (0, 255, 0), 1)


        if ratio <= .9 or mar > 1.1 :
            COUNTER += 1
        else:
            if COUNTER >= 15:
                TOTAL += 1
                frame = vs.read()
                time.sleep(.3)
                frame2= frame.copy()
                img_name = "opencv_frame_{}.png".format(TOTAL)
                #cv2.imwrite(img_name, frame)
                print("{} written!".format(img_name))
            COUNTER = 0

        cv2.putText(frame, "the ratio from l1 and l2 is: {}".format(distance), (10, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 255), 2)

    cv2.imshow("Frame", frame)
    fps.update()

    key2 = cv2.waitKey(1) & 0xFF
    if key2 == ord('q'):
        break
fps.stop()


cv2.destroyAllWindows()
vs.stop()

现在我的问题是我不知道如何计算两个地标之间的距离,我在需要帮助的地方在代码中发表了评论。

如果有人能帮助我,我将不胜感激,在此先感谢

完成了我使用的条件是

l1= math.sqrt((jaw[0][0]-nose[1][0])**2+(jaw[0][1]-nose[1][1])**2)
            l2 = math.sqrt((jaw[16][0]-nose[1][0])**2+(jaw[16][1]-nose[1][1])**2)
            ratio = l1/l2
            m = (jaw[0][1]-jaw[16][1])/(jaw[0][0]-jaw[16][0])
            if (ratio <= 1.1 and ratio > .9) :
                cond1 = True
            else:
                cond1= False
            if (jaw[0][1]<= (nose[1][1]+5) and jaw[0][1]> (nose[1][1]-5)):
                cond2 = True
            else:
                cond2= False
            if (m <= .05 and m >-.05 ):
                cond3 = True
            else:
                cond3= False

大意是jaw[0]表示属于0点的点(x,y) jaw

所以当 jaw[0] 和 nose[1] 之间的距离与 jaw[16] 和 nose[1] 之间的距离相似时,cond1 为真

当下巴的 y 坐标与鼻子的 y 坐标相似时,cond2 为真

最后一个条件是关于下巴[0]和下巴[16]之间的夹角