Created
June 18, 2013 18:49
-
-
Save philipcristiano/5808137 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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