Skip to content

Instantly share code, notes, and snippets.

@ritwikraha
Created April 15, 2020 11:30
Show Gist options
  • Save ritwikraha/7b344d32f4cb1c4114d0140f2b2eeadf to your computer and use it in GitHub Desktop.
Save ritwikraha/7b344d32f4cb1c4114d0140f2b2eeadf to your computer and use it in GitHub Desktop.
import cv2
import numpy as np
import dlib
cap = cv2.VideoCapture(0)
detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")
while True:
_, frame = cap.read()
# converting to grayscale since we only need grayscale information for prediction
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = detector(gray)
for face in faces:
landmarks = predictor(gray, face)
for n in range(0, 68):
x = landmarks.part(n).x
y = landmarks.part(n).y
cv2.circle(frame, (x, y), 4, (255, 0, 0), -1)
cv2.imshow("Landmark points", frame)
key = cv2.waitKey(1)
if key == 27:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment