Skip to content

With the Mediapipe library we can put up to 468 landmark in our face

Notifications You must be signed in to change notification settings

Michael-BJ/Face-Mesh-Mediapipe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

How it's works

  1. First import the library that we need
import cv2
import mediapipe as mp
  1. Make the program to connect to the webcam
import cv2
import numpy as numpy

cap = cv2.VideoCapture(0)
while True:
    _, frame = cap.read()
    cv2.imshow('Face Mesh', frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

cap.release()
cv2.destroyAllWindows()
  1. Load the module of face_mesh and drawing_utils
mp_drawing = mp.solutions.drawing_utils
mp_face_mesh = mp.solutions.face_mesh
  1. Determine the minimum percentage
with mp_face_mesh.FaceMesh(
    min_detection_confidence=0.5,
    min_tracking_confidence=0.5) as face_mesh:
  1. Chanfe BGR to RGB
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
  1. To optimize the program change writeable to False
image.flags.writeable = False
  1. processing
results = hands.process(image)
  1. Change RGB to BGR
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
  1. Make a loop and draw the landmark
drawing_spec = mp_drawing.DrawingSpec(color=(0,251,251),thickness=1, circle_radius=1)

if results.multi_face_landmarks:
            for face_landmarks in results.multi_face_landmarks:
                mp_drawing.draw_landmarks(image,face_landmarks,mp_face_mesh.FACE_CONNECTIONS,drawing_spec,drawing_spec)

About

With the Mediapipe library we can put up to 468 landmark in our face

Topics

Resources

Stars

Watchers

Forks

Languages