Skip to content

Instantly share code, notes, and snippets.

@sunnycyk
Created May 14, 2014 07:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sunnycyk/730957e0a24f82e4bf5f to your computer and use it in GitHub Desktop.
Save sunnycyk/730957e0a24f82e4bf5f to your computer and use it in GitHub Desktop.
Pi Face Detection
import cv2
import cv2.cv as cv
import config
import picamera
def detect_faces(image):
haar_faces = cv2.CascadeClassifier(config.HAAR_FACES)
detected = haar_faces.detectMultiScale(image, scaleFactor=config.HAAR_SCALE_FACTOR,
minNeighbors=config.HAAR_MIN_NEIGHBORS,
minSize=config.HAAR_MIN_SIZE,
flags=cv2.CASCADE_SCALE_IMAGE)
return detected
if __name__ == "__main__":
with picamera.PiCamera() as camera:
camera.capture('myface.jpg')
image = cv2.imread('myface.jpg')
faces = detect_faces(image)
if len(faces) != 0:
for (x,y,w,h) in faces:
cv2.rectangle(image, (x, y), (x+w, y+h), 255)
cv2.imwrite('detect.jpg', image)
else:
print 'No Face Detected'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment