當前位置: 首頁>>代碼示例>>Python>>正文


Python face_recognition.face_landmarks方法代碼示例

本文整理匯總了Python中face_recognition.face_landmarks方法的典型用法代碼示例。如果您正苦於以下問題:Python face_recognition.face_landmarks方法的具體用法?Python face_recognition.face_landmarks怎麽用?Python face_recognition.face_landmarks使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在face_recognition的用法示例。


在下文中一共展示了face_recognition.face_landmarks方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: detect_landmarks

# 需要導入模塊: import face_recognition [as 別名]
# 或者: from face_recognition import face_landmarks [as 別名]
def detect_landmarks(face_img):
    landmakrs = face_recognition.face_landmarks(face_img)
    return landmakrs[0] if len(landmakrs) > 0 else None 
開發者ID:albertpumarola,項目名稱:GANimation,代碼行數:5,代碼來源:face_utils.py

示例2: show_facial_features

# 需要導入模塊: import face_recognition [as 別名]
# 或者: from face_recognition import face_landmarks [as 別名]
def show_facial_features(image_path):

    # Load the jpg file into an array
    image = face_recognition.load_image_file(image_path)

    # these are the features that will be detected and shown
    facial_features = [
        'chin',
        'left_eyebrow',
        'right_eyebrow',
        'nose_bridge',
        'nose_tip',
        'left_eye',
        'right_eye',
        'top_lip',
        'bottom_lip']

    blue = ImageColor.getcolor('blue', 'RGB')

    # Find all facial landmarks for all the faces in the image
    face_landmarks_list = face_recognition.face_landmarks(image)
    img_obj = Image.fromarray(image)

    # draw lines upon facial features
    for face_landmarks in face_landmarks_list:
        drawing = ImageDraw.Draw(img_obj)
        for facial_feature in facial_features:
            drawing.line(face_landmarks[facial_feature], width=2, fill=blue)

    # show image
    img_obj.show() 
開發者ID:PacktPublishing,項目名稱:Python-for-Everyday-Life,代碼行數:33,代碼來源:detect_facial_features.py

示例3: main

# 需要導入模塊: import face_recognition [as 別名]
# 或者: from face_recognition import face_landmarks [as 別名]
def main():
    closed_count = 0
    video_capture = cv2.VideoCapture(0)

    ret, frame = video_capture.read(0)
    # cv2.VideoCapture.release()
    small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
    rgb_small_frame = small_frame[:, :, ::-1]

    face_landmarks_list = face_recognition.face_landmarks(rgb_small_frame)
    process = True

    while True:
        ret, frame = video_capture.read(0)

        # get it into the correct format
        small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
        rgb_small_frame = small_frame[:, :, ::-1]



        # get the correct face landmarks
        
        if process:
            face_landmarks_list = face_recognition.face_landmarks(rgb_small_frame)

            # get eyes
            for face_landmark in face_landmarks_list:
                left_eye = face_landmark['left_eye']
                right_eye = face_landmark['right_eye']


                color = (255,0,0)
                thickness = 2

                cv2.rectangle(small_frame, left_eye[0], right_eye[-1], color, thickness)

                cv2.imshow('Video', small_frame)
                cv2.waitKey(1)

                ear_left = get_ear(left_eye)
                ear_right = get_ear(right_eye)

                closed = ear_left < 0.2 and ear_right < 0.2

                if (closed):
                    closed_count += 1

                else:
                    closed_count = 0

                if (closed_count >= EYES_CLOSED_SECONDS):
                    asleep = True
                    while (asleep): #continue this loop until they wake up and acknowledge music
                        print("EYES CLOSED")

                        if (kb.is_pressed('space')):
                            asleep = False
                    closed_count = 0

        process = not process 
開發者ID:ageitgey,項目名稱:face_recognition,代碼行數:63,代碼來源:blink_detection.py


注:本文中的face_recognition.face_landmarks方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。