Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from imutils import face_utils
- import numpy as np
- import argparse
- import imutils
- import dlib
- import cv2
- import time
- import math
- from imutils.video import VideoStream
- def rass(x1,y1,x2,y2):
- return math.sqrt((x2-x1)**2+(y2-y1)**2)
- detector = dlib.get_frontal_face_detector()
- predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')
- vs = VideoStream().start()
- time.sleep(2.0)
- while True:
- frame = vs.read()
- frame = imutils.resize(frame, width=500)
- gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
- rects = detector(gray, 0)
- for (i, rect) in enumerate(rects):
- shape = predictor(gray, rect)
- shape = face_utils.shape_to_np(shape)
- (x, y, w, h) = face_utils.rect_to_bb(rect)
- cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
- cv2.putText(frame, "Face #{}".format(i + 1), (x - 10, y - 10),
- cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
- cv2.imshow("Frame", frame)
- key = cv2.waitKey(1) & 0xFF
- if key == ord("q"):
- break
- cv2.destroyAllWindows()
- vs.stop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement