Face Detection

What is face detection?

import cv2 #opencv is a library to do image detection
cap=cv2.VideoCapture(0)#webcam object

if not cap.isOpened():#to check or errors
raise IOError("webcam cannot start")

face_cascade=cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

while True:
ret,frame=cap.read()
gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
frame=cv2.resize(frame,None,fx=0.5,fy=0.5,interpolation=cv2.INTER_AREA)#to draw the frame 
faces=face_cascade.detectMultiScale(gray,1.1,4)
for (x,y,w,h) in faces:#to get coordinates
cv2.rectangle(frame,(x,y),(w,h),(255,0,0),2)


cv2.imshow('Input',frame)
c=cv2.waitKey(1)

if c==ord('q'):
break
cap.release()
cv2.destroyAllWindows()