def center_from_faces(matrix):
face_cascade = cv2.CascadeClassifier(cascade_path)
faces = face_cascade.detectMultiScale(matrix, FACE_DETECT_REJECT_LEVELS, FACE_DETECT_LEVEL_WEIGHTS)
x, y = (0, 0)
weight = 0
# iterate over our faces array
for (x, y, w, h) in faces:
print('Face detected at ', x, y, w, h)
weight += w * h
x += (x + w / 2) * w * h
y += (y + h / 2) * w * h
if len(faces) == 0:
return False
return {
'x': x / weight,
'y': y / weight,
'count': len(faces)
}
评论列表
文章目录