Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #Import required modules
  2. import cv2
  3. import dlib
  4.  
  5. #Set up some required objects
  6. video_capture = cv2.VideoCapture(0) #Webcam object
  7. detector = dlib.get_frontal_face_detector() #Face detector
  8. predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat") #Landmark identifier. Set the filename to whatever you named the downloaded file
  9.  
  10. while True:
  11. ret, frame = video_capture.read()
  12. gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  13. clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8))
  14. clahe_image = clahe.apply(gray)
  15.  
  16. detections = detector(clahe_image, 1) #Detect the faces in the image
  17.  
  18. for k,d in enumerate(detections): #For each detected face
  19.  
  20. shape = predictor(clahe_image, d) #Get coordinates
  21. for i in range(1,68): #There are 68 landmark points on each face
  22. cv2.circle(frame, (shape.part(i).x, shape.part(i).y), 1, (0,0,255), thickness=2) #For each point, draw a red circle with thickness2 on the original frame
  23.  
  24. cv2.imshow("image", frame) #Display the frame
  25.  
  26. if cv2.waitKey(1) & 0xFF == ord('q'): #Exit program when the user presses 'q'
  27. break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement