Created
June 2, 2014 16:40
-
-
Save mike-seiler/899b106a15d912df4213 to your computer and use it in GitHub Desktop.
easy face detection
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
import cv2 | |
""" | |
wget http://eclecti.cc/files/2008/03/haarcascade_frontalface_alt.xml | |
""" | |
def detect(path): | |
img = cv2.imread(path) | |
cascade = cv2.CascadeClassifier("haarcascade_frontalface_alt.xml") | |
rects = cascade.detectMultiScale(img, 1.3, 4, cv2.cv.CV_HAAR_SCALE_IMAGE, (20,20)) | |
if len(rects) == 0: | |
return [], img | |
rects[:, 2:] += rects[:, :2] | |
return rects, img | |
def box(rects, img): | |
for x1, y1, x2, y2 in rects: | |
print 'face' | |
cv2.rectangle(img, (x1, y1), (x2, y2), (127, 255, 0), 2) | |
cv2.imwrite('detected.jpg', img); | |
import sys | |
rects, img = detect(sys.argv[1]) | |
box(rects, img) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment