-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFaceDetection.py
32 lines (24 loc) · 882 Bytes
/
FaceDetection.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
#!/usr/bin/env python
# coding: utf-8
# In[44]:
class fd:
def face(self):
try:
import cv2
classifier = cv2.CascadeClassifier("Essentials/haarcascade_frontalface_default.xml")
cam = cv2.VideoCapture(0)
while True:
temp , img = cam.read()
if temp:
faces = classifier.detectMultiScale(img,1.3,5)
for x,y,w,h in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,0),2)
cv2.putText(img,"Detected",(x,y-20),cv2.FONT_HERSHEY_COMPLEX,.6,(0,255,0),1)
cv2.imshow("img",img)
if cv2.waitKey(1) == 13:
break
cam.release()
cv2.destroyAllWindows()
return 1
except:
return 0