Sumitj990 commited on
Commit
75a40ea
·
verified ·
1 Parent(s): 7afaa94

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import pyttsx3
3
+ import datetime
4
+
5
+ engine = pyttsx3.init('sapi5')
6
+ voices = engine.getProperty('voices')
7
+ # print(voices[1].id)
8
+ engine.setProperty('voice', voices[0].id)
9
+
10
+
11
+ def speak(audio):
12
+ engine.say(audio)
13
+ engine.runAndWait()
14
+
15
+
16
+ cap = cv2.VideoCapture(0)
17
+ face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
18
+ smile_cascade = cv2.CascadeClassifier('haarcascade_smile.xml')
19
+ eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml')
20
+ while True:
21
+ _, frame = cap.read()
22
+ gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
23
+ face = face_cascade.detectMultiScale(gray, 1.3, 4)
24
+ for x, y, w, h in face:
25
+ #cv2.rectangle(frame, (x,y), (x+w, y+h), (0, 255, 255), 2)
26
+ face_roi = frame[x:x+w, y:y+h]
27
+ gray_roi = gray[x:x+w, y:y+h]
28
+ eye = eye_cascade.detectMultiScale(gray_roi, 1.3, 50)
29
+ for x1, y1, w1, h1 in eye:
30
+ #cv2.rectangle(face_roi, (x1, y1), (x1+w1, y1+h1), (0, 0, 255), 2)
31
+ smile = smile_cascade.detectMultiScale(gray_roi, 1.3, 25)
32
+ for x1, y1, w1, h1 in smile:
33
+ #cv2.rectangle(face_roi, (x1, y1), (x1+w1, y1+h1), (0, 0, 255), 2)
34
+ timestamp = datetime.datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
35
+ filename = f'selfie-{timestamp}.png'
36
+ cv2.imwrite(filename, frame)
37
+ speak("Selfie taken")
38
+
39
+ cv2.imshow('cam star', frame)
40
+ if cv2.waitKey(10) == ord('q'):
41
+ break