Skip to content

Instantly share code, notes, and snippets.

@jjone36
Created March 30, 2019 07:43
Show Gist options
  • Save jjone36/c63da86686347651bb988dd4c015e55b to your computer and use it in GitHub Desktop.
Save jjone36/c63da86686347651bb988dd4c015e55b to your computer and use it in GitHub Desktop.
import cv2
import numpy as np
# Step 1. Define detect function
face_cascade = cv2.CascadeClassifier('haarcascades/haarcascade_frontalface_default.xml')
def detect_face(img):
img_copy = img.copy()
face_rects = face_cascade.detectMultiScale(img_copy)
for (x, y, w, h) in face_rects:
cv2.rectangle(img_copy, (x, y), (x+w, y+h), (255, 255, 255), 3)
return img_copy
# Step 2. Call the cam
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read(0)
frame = detect_face(frame)
cv2.imshow('Video Face Detection', frame)
c = cv2.waitKey(1)
if c == 27:
break
cap.release()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment