-
Notifications
You must be signed in to change notification settings - Fork 1
/
Face_identification.py
34 lines (25 loc) · 1.13 KB
/
Face_identification.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import cv2
video = cv2.VideoCapture(0)
# load "haarcascade_frontalface_default.xml" by creating a CascadeClassifier
# object as cascade
cascade = cv2.CascadeClassifier("haarcascade_frontalface_default.xml")
while True:
check,frame = video.read()
# Image from webacm is in the format of BGR i.e combination of 3 colours
# which will basicall require more amount of computation.
# so we convert it into a gray scale image which is only single colour
# and requires less computation.
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
# Now we use detectMultiScale method to detect the faces in the video
# stream. Which will return x,y,w,h which are basically the positions
# with which we create a rectangle box.
face = cascade.detectMultiScale(gray, scaleFactor = 1.1, minNeighbors = 6)
# using for loop to go through the locations x,y,w,h and drow a rectangle
for x,y,w,h in face:
frame = cv2.rectangle(frame, (x,y), (x+w,y+h), (0,255,255), 3)
cv2.imshow("Video",frame)
key = cv2.waitKey(1)
if(key == ord('q')):
break
video.release()
cv2.destroyAllWindows()