In [1]:
from imutils.video import VideoStream
from imutils import face_utils
import datetime
import numpy as np
import math
import argparse
import imutils
import time
import dlib
import cv2


def calcDist(a,b):
return math.sqrt((a[0]-b[0])*(a[0]-b[0]) + (a[1]-b[1])*(a[1]-b[1]))

def findDist(mat):
    oo = calcDist(shape[0], shape[16])
    om = (calcDist(shape[0], shape[8]) + calcDist(shape[8], shape[16]) )/ 2
    egeg = calcDist(shape[36], shape[39])
        eded = calcDist(shape[42], shape[45])
        bgbd = calcDist(shape[48], shape[54])
        ngnd = calcDist(shape[31], shape[35])

	return  [oo, om, egeg, eded, bgbd, ngnd]

def fill(shape, frame):
	oeilgauche = [shape[36:42]]
	oeildroit = [shape[42:48]]
	bouche = [shape[48:60]]

	nez = []
	partiegauche = []
	partiedroite = []
	partiebasse = []


	nez.append([shape[27][0],shape[27][1]])
	for i in range(31, 36, 1):
		nez.append([shape[i][0],shape[i][1]])


	for i in range(0, 6, 1):
		partiegauche.append([shape[i][0],shape[i][1]])
	for i in (48,31,36):
		partiegauche.append([shape[i][0],shape[i][1]])


	for i in range(11, 17, 1):
		partiedroite.append([shape[i][0],shape[i][1]])
	for i in (45,35,54):
		partiedroite.append([shape[i][0],shape[i][1]])


	for i in range(54, 60, 1):
		partiebasse.append([shape[i][0],shape[i][1]])
	partiebasse.append([shape[48][0],shape[48][1]])
	for i in range(5, 12, 1):
		partiebasse.append([shape[i][0],shape[i][1]])


	return oeilgauche, oeildroit, bouche, [np.asarray(nez)], [np.asarray(partiebasse)], [np.asarray(partiegauche)], [np.asarray(partiedroite)]

"""
	cv2.fillPoly(frame, oeildroit, (255,255,0))
	cv2.fillPoly(frame, oeilgauche, (255,255,0))
	cv2.fillPoly(frame, bouche, (255,0,255))
	cv2.fillPoly(frame, [np.asarray(nez)], (255,0,255))
	cv2.fillPoly(frame, [np.asarray(partiebasse)], (255,125,255))
	cv2.fillPoly(frame, [np.asarray(partiedroite)], (0,255,255))
	cv2.fillPoly(frame, [np.asarray(partiegauche)], (0,0,255))
"""



def histo(shape, frame):


	mask = np.zeros(frame.shape, dtype=np.uint8)
	print shape
	roi_corners = shape
	channel_count = frame.shape[2]
	ignore_mask_color = (255,)*channel_count
	masked_image = cv2.bitwise_and(frame, mask)
	cv2.fillPoly(mask, roi_corners, ignore_mask_color)
	#cv2.fillPoly(masked_image, [np.asarray(shape[2])], (0,0,255))
	cv2.imshow('mask', masked_image)


def fillForm(shape):
	pass




def dist2vect(vect1, vect2):
	tmp = 0
	for a in range(len(vect1)):
		tmp += int((vect1[a] - vect2[a])) * int((vect1[a] - vect2[a]))
	return tmp

ap = argparse.ArgumentParser()
ap.add_argument("-r", "--picamera", type=int, default=-1,
	help="whether or not the Raspberry Pi camera should be used")
args = vars(ap.parse_args())

detector = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor('shape_predictor_68_face_landmarks.dat')

vs = VideoStream(usePiCamera=args["picamera"] > 0).start()


val = []
while True:

	frame = vs.read()
	frame = imutils.resize(frame, width=400)
	gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
	rects = detector(gray, 0)
	tmp = []

	for rect in rects:

		shape = predictor(gray, rect)
		shape = face_utils.shape_to_np(shape)
		tmp = findDist(shape)

		for (x, y) in shape:
			cv2.circle(frame, (x, y), 1, (0, 0, 255), -1)

		a = fill(shape, frame)
		histo(a[2][0],frame)



	key = cv2.waitKey(1) & 0xFF


	if key == ord("q"):
		exit()
		break


	cv2.imshow("Frame", frame)

cv2.destroyAllWindows()
vs.stop()


usage: __main__.py [-h] [-r PICAMERA]
__main__.py: error: unrecognized arguments: -f C:\Users\Aoda\AppData\Roaming\jupyter\runtime\kernel-892ccc5f-00db-42cd-af5b-278514fe9bb2.json
An exception has occurred, use %tb to see the full traceback.

SystemExit: 2
C:\Users\Aoda\Anaconda2\lib\site-packages\IPython\core\interactiveshell.py:2889: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.
  warn("To exit: use 'exit', 'quit', or Ctrl-D.", stacklevel=1)

In [ ]: