Created
March 9, 2020 14:36
-
-
Save elbruno/0c7d526ad74f468ce206ceba37f873dc to your computer and use it in GitHub Desktop.
FaceDetectionUsingOpenCvHaarCascades.py
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
# Bruno Capuano | |
# detect faces using haar cascades from https://github.com/opencv/opencv/tree/master/data/haarcascades | |
import cv2 | |
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') | |
cap = cv2.VideoCapture(0) | |
while True: | |
_, frame = cap.read() | |
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) | |
faces = face_cascade.detectMultiScale(gray, 1.3, 5) | |
for (top, right, bottom, left) in faces: | |
cv2.rectangle(frame,(top,right),(top+bottom,right+left),(0,0,255),2) | |
cv2.imshow('Face Detection',frame) | |
k = cv2.waitKey(30) & 0xff | |
if k == 27: | |
break | |
cap.release() | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment