- First download the library that we need
pip install opencv-python
pip install numpy
pip install dlib
pip install imutils
- Connect the webcam to the program
cap = cv2.VideoCapture(0)
while True:
_, frame = cap.read()
cv2.imshow('Facial Landmark', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
- Make the program to target or detect the face
detector = dlib.get_frontal_face_detector()
- Insert the libary that we need
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
- Change the BGR to the grayscale
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
- Detect the face in the grayscale image
- Convert the coordinates of facial landmark to a numpy
point = predictor(gray, face)
points = face_utils.shape_to_np(point)
- Draw a point in a face
for (x, y) in points :
cv2.circle(frame, (x, y), 1, (0, 0, 255), 3)
Clik the picture to see the Video
![Watch the video](https://camo.githubusercontent.com/5ad1ade5d1b6e2b6821f46b9c74fa0ea8dfeb2400f39faa95d2d5eae696be205/68747470733a2f2f696d672e796f75747562652e636f6d2f76692f5a4174505a6768735f59342f6d617872657364656661756c742e6a7067)