-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
30 lines (26 loc) · 1.02 KB
/
main.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
import cv2
video = cv2.VideoCapture(0)
faceCascade = cv2.CascadeClassifier("dataset/haarcascade_frontalface_default.xml")
smileCascade = cv2.CascadeClassifier("dataset/haarcascade_smile.xml")
while True:
success,img = video.read()
grayImg = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(grayImg,1.1,4)
cnt=1
keyPressed = cv2.waitKey(1)
for x,y,w,h in faces:
img = cv2.rectangle(img,(x,y),(x+w,y+h),(0,255,247),3)
smiles = smileCascade.detectMultiScale(grayImg,1.8,15)
for x,y,w,h in smiles:
img = cv2.rectangle(img,(x,y),(x+w,y+h),(100,206,47),3)
print("Image "+str(cnt)+"Saved")
path=r'C:\\Users\\DELL\\Pictures\\project images\\img'+str(cnt)+'.jpg'
cv2.imwrite(path,img)
cnt +=1
if(cnt>=4):
break
cv2.imshow('live video',img)
if(keyPressed & 0xFF==ord('q')):
break
video.release()
cv2.destroyAllWindows()