Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit 6067061

Browse files
authored
updated face_detection.py
1 parent c6c06c7 commit 6067061

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
import cv2 ##Import OpenCv
22

33
face = cv2.CascadeClassifier('C:/Users/91976/Desktop/haarcascade_frontalface_default.xml') ##'haarcascade_frontalface_default.xml' an opencv classifier for face detection
4-
5-
cap = cv2.VideoCapture(0) ##capturevideo by webcam or your laptop default cam for webcame => 1 and for defalut laptop camera => 2
4+
cap = cv2.VideoCapture(0) ##capturevideo by webcam or your laptop default cam for webcame => 1 and for defalut laptop camera => 2
65

76
while True:
8-
sucess,img=cap.read()
9-
10-
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) ##before detecting face you should convert img or video into gray image
11-
faces=face.detectMultiScale(gray,1.1,5)
7+
sucess,img = cap.read()
8+
gray = cv2.cvtColor( img , cv2.COLOR_BGR2GRAY ) ##before detecting face you should convert img or video into gray image
9+
faces = face.detectMultiScale( gray ,1.1 ,5 )
1210

1311
for ( x , y , w , h) in faces:
1412
cv2.rectangle(img,( x , y ),( x*w , y*h ),(255,0,0),2) ##will create the rectangle where face is detected
1513

1614
cv2.imshow('img',img)
17-
k=cv2.waitKey(30) & 0xff
18-
if k==27:
15+
k = cv2.waitKey(30) & 0xff
16+
if k == 27:
1917
break
2018

21-
cap.release()
19+
cap.release()

0 commit comments

Comments
 (0)