Advertisement
MagicWinnie

Untitled

Mar 18th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.10 KB | None | 0 0
  1. from imutils import face_utils
  2. import numpy as np
  3. import argparse
  4. import imutils
  5. import dlib
  6. import cv2
  7. import time
  8. import math
  9. from imutils.video import VideoStream
  10. def rass(x1,y1,x2,y2):
  11.       return math.sqrt((x2-x1)**2+(y2-y1)**2)
  12. detector = dlib.get_frontal_face_detector()
  13. predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')
  14. vs = VideoStream().start()
  15. time.sleep(2.0)
  16. while True:
  17.       frame = vs.read()
  18.       frame = imutils.resize(frame, width=500)
  19.       gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
  20.       rects = detector(gray, 0)
  21.       for (i, rect) in enumerate(rects):
  22.             shape = predictor(gray, rect)
  23.             shape = face_utils.shape_to_np(shape)
  24.             (x, y, w, h) = face_utils.rect_to_bb(rect)
  25.             cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
  26.             cv2.putText(frame, "Face #{}".format(i + 1), (x - 10, y - 10),
  27.         cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
  28.       cv2.imshow("Frame", frame)
  29.       key = cv2.waitKey(1) & 0xFF
  30.       if key == ord("q"):
  31.             break
  32. cv2.destroyAllWindows()
  33. vs.stop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement