Last active
February 18, 2016 08:38
-
-
Save PeaceAndHiLight/54b9004f68e49c81e0ed to your computer and use it in GitHub Desktop.
OpenCV Face Detect
This file contains 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
#coding: utf-8 | |
import cv2 | |
import numpy as np | |
faceCascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') | |
img = cv2.imread('image.jpg', cv2.IMREAD_COLOR) | |
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
face = faceCascade.detectMultiScale(gray, 1.1, 3) | |
if len(face) > 0: | |
for rect in face: | |
cv2.rectangle(img, tuple(rect[0:2]), tuple(rect[0:2]+rect[2:4]), (0, 0,255), thickness=2) | |
else: | |
print "no face" | |
cv2.imwrite('detected.jpg', img) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment