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=400)
- gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
- rects = detector(gray, 0)
- for rect in rects:
- shape = predictor(gray, rect)
- shape = face_utils.shape_to_np(shape)
- for (x, y) in shape:
- cv2.circle(frame, (x, y), 1, (0, 0, 255), -1)
- if ((shape[0][0]-shape[17][0])<5) and ((shape[0][0]-shape[17][0])>-5):
- cv2.rectangle(frame, (30, 200), (230, 300), (0, 255, 0), 5)
- elif ((shape[26][0]-shape[16][0])<5) and ((shape[26][0]-shape[16][0])>-5):
- cv2.rectangle(frame, (400, 200), (600, 300), (0, 255, 0), 5)
- elif ((shape[16][1]-shape[26][1])<1) and ((shape[0][1]-shape[17][1])<1):
- cv2.rectangle(frame, (230, 350), (400, 450), (0, 255, 0), 5)
- elif ((shape[16][1]-shape[26][1])>30) and ((shape[0][1]-shape[17][1])>30):
- cv2.rectangle(frame, (230, 30), (400, 130), (0, 255, 0), 5)
- else:
- cv2.rectangle(frame, (230, 200), (400, 300), (0, 255, 0), 5)
- 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