# OpenCV: Face Detection using Haar Cascades

Alex Egg,

I had the privilege to take Dr. Freund last year for a grad class – he is one of the principle innovators behind boosting. I remember he was going over one particularly interesting case study of Adaboost: the Haar faces. It was a tree-based model that used a convolutional trick to learn the face features of a human.

Incidentally I found a cool openCV script w/ a pre-trained Haar model that runs on your laptop webcam:

import cv2
import numpy as np

c = cv2.VideoCapture(0)

# get the xmls from https://github.com/Itseez/opencv/tree/master/data/haarcascades

while(1):

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

for (x,y,w,h) in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
roi_gray = gray[y:y+h, x:x+w]
roi_color = img[y:y+h, x:x+w]
for (ex,ey,ew,eh) in eyes:
cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)

cv2.imshow('img',img)
if cv2.waitKey(5)==27:
break
cv2.destroyAllWindows()