Skip to content

Commit 5991a21

Browse files
authored
Create Video_face.py (GeeksforGeeks-VIT-Bhopal#82)
* Create stop_watch.py * Create Calculation_code.py * Create Video_face.py
1 parent 12539de commit 5991a21

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Face Detection/Video_face.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import cv2
2+
face_cascade=cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
3+
eye_cascade=cv2.CascadeClassifier('haarcascade_eye.xml')
4+
5+
6+
cap = cv2.VideoCapture(0)
7+
while 1:
8+
9+
ret, img = cap.read()
10+
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
11+
# Detects faces of different sizes in the input image
12+
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
13+
14+
for (x,y,w,h) in faces:
15+
16+
cv2.rectangle(img,(x,y),(x+w,y+h),(255,255,0),2)
17+
roi_gray = gray[y:y+h, x:x+w]
18+
roi_color = img[y:y+h, x:x+w]
19+
20+
eyes = eye_cascade.detectMultiScale(roi_gray)
21+
22+
23+
for (ex,ey,ew,eh) in eyes:
24+
cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,127,255),2)
25+
26+
27+
cv2.imshow('img',img)
28+
k = cv2.waitKey(30) & 0xff
29+
if k == 27:
30+
break
31+
32+
cap.release()
33+
34+
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)