Python face_recognition.face_landmarks() Examples

The following are 3 code examples of face_recognition.face_landmarks(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module face_recognition , or try the search function .
Example #1
Source File: face_utils.py    From GANimation with GNU General Public License v3.0 5 votes vote down vote up
def detect_landmarks(face_img):
    landmakrs = face_recognition.face_landmarks(face_img)
    return landmakrs[0] if len(landmakrs) > 0 else None 
Example #2
Source File: detect_facial_features.py    From Python-for-Everyday-Life with MIT License 5 votes vote down vote up
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() 
Example #3
Source File: blink_detection.py    From face_recognition with MIT License 4 votes vote down vote up
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