Created
March 8, 2021 20:09
-
-
Save yokeshrana/9d9cff8ec3044c77934add63aa6f387c to your computer and use it in GitHub Desktop.
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
''' | |
Face Detection | |
-> Using method used by Viola and jones (real time object detection) | |
-> We will use lot of images with positive faces and negative faces and will train the cascade file to detect the faces | |
-> In Open CV we dont have to actually do this we can use trained cascade file to detect things | |
''' | |
import cv2 | |
faceCascade = cv2.CascadeClassifier("Resources/haarcascade_frontalface_default.xml") | |
img = cv2.imread("Resources/lena.png") | |
imgGray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) | |
faces = faceCascade.detectMultiScale(imgGray,1.1,4) | |
for (x,y,w,h) in faces: | |
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2) | |
cv2.imshow("Result",img) | |
cv2.waitKey(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment