Skip to content

Instantly share code, notes, and snippets.

@smitshilu
Last active February 4, 2019 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smitshilu/1a44c5f615b23720384ba90a63fcd549 to your computer and use it in GitHub Desktop.
Save smitshilu/1a44c5f615b23720384ba90a63fcd549 to your computer and use it in GitHub Desktop.
OpenCV face detection
# Initialize video_capture to get camera feed
video_capture = cv2.VideoCapture(0)
video_capture.set(3, 320)
video_capture.set(4, 240)
# Grab a single frame from WebCam
ret, frame = video_capture.read()
# Initialize haar cascade
detect_faces = cv2.CascadeClassifier('haarcascade_frontalface_alt2.xml')
# Find all the faces and face enqcodings in the frame
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = detect_faces.detectMultiScale(gray, 1.3,5)
# Store all the faces locations in one list
face_locations = []
for (x,y,w,h) in faces:
temp_tuple = (y, x+w, y+h, x)
face_locations.append(temp_tuple)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment