In [7]:
import numpy as np
import cv2
import math
cap = cv2.VideoCapture(0)
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
def frame2vect(face):
#transforme l'image en vect
try:
cv2.imshow('bob', face)
#face = cv2.resize(face,None,fx=200/len(face[0]), fy=200/len(face[1]), interpolation = cv2.INTER_CUBIC)
a = face.flatten()
#print len(a)
return a
except:
pass
def reduceMat(mat):
red = np.zeros((len(mat)/4, len(mat)/4))
try:
for i in range(len(mat)/4):
for j in range(len(mat)/4):
red[i,j] = (mat[i*4,j*4] + mat[i*4+1,j*4] + mat[i*4,j*4+1] + mat[i*4+1,j*4+1])
cv2.imshow('bab', red)
except:
pass
def checkIn(vect):
#obj : voir la presence dans fichier ref
pass
def dist2vect(vect1, vect2):
tmp = 0
for a in range(len(vect1)):
tmp += (vect1[a] - vect[2]) * (vect1[a] - vect[2])
return math.sqrt(tmp)
while(True):
#Capture le flux video
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# preprocess
gray = cv2.equalizeHist(gray)
faces = face_cascade.detectMultiScale(gray, 2, 5)
for (x,y,w,h) in faces:
#a = frame2vect(gray[y:y+h,x:x+w])
#print w,h
reduceMat(gray[y:y+h,x:x+w])
#print frame[x:x+w,y:y+h]
cv2.rectangle(gray,(x,y),(x+w,y+h),(255,0,0),2)
#face = man[x:x+w,y:y+h]
# Affiche le result
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
In [ ]:
In [ ]:
In [ ]: