def face_detect(self, img):
""" Detect the face location of the image img, using Haar cascaded face detector of OpenCV.
return : x,y w, h of the bouning box.
"""
face_cascade = cv2.CascadeClassifier('../haarcascades/haarcascade_frontalface_default.xml')
faces = face_cascade.detectMultiScale(img, 1.3, 5)
x = -1
y = -1
w = -1
h = -1
if len(faces) == 1: # we take only when we have 1 face, else, we return nothing.
x,y,w,h = faces[0]
else:
## for (x_,y_,w_,h_) in faces:
## x = x_
## y = y_
## w = w_
## h = h_
## break # we take only the first face,
print "More than one face!!!!!!!!!"
return x,y,w,h
评论列表
文章目录