Skip to content

Instantly share code, notes, and snippets.

@philipcristiano
Created June 18, 2013 18:49
Show Gist options
  • Save philipcristiano/5808137 to your computer and use it in GitHub Desktop.
Save philipcristiano/5808137 to your computer and use it in GitHub Desktop.
def faces_from_pil_image(pil_image):
"Return a list of (x,y,h,w) tuples for faces detected in the PIL image"
storage = cv.CreateMemStorage(0)
facial_features = cv.Load('haarcascade_frontalface_alt.xml', storage=storage)
cv_im = cv.CreateImageHeader(pil_image.size, cv.IPL_DEPTH_8U, 3)
cv.SetData(cv_im, pil_image.tostring())
faces = cv.HaarDetectObjects(cv_im, facial_features, storage)
# faces includes a `neighbors` field that we aren't going to use here
return [f[0] for f in faces]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment