-
Notifications
You must be signed in to change notification settings - Fork 0
/
add person.py
59 lines (49 loc) · 1.76 KB
/
add person.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import pyttsx3
import speech_recognition as sr
from cv2 import cv2
#import pyaudio
'''using this script to create a folder for a person imags with his name using audio input
2 module usage
1. pyttsx3 --- for converting text to speech ( useful in saying commands like listening)
2. speech recognition --- for speech to text and it uses google speech recognition
3. creates a folder for the listned name
4. using webcam captures 30 images of unknown person for trainning
'''
r=sr.Recognizer()
face_status='unknown'
def savecmd():
eng=pyttsx3.init()
print("Listening name....")
eng.say('Listening name') #(1)
eng.runAndWait()
with sr.Microphone() as source2:
try:
r.adjust_for_ambient_noise(source2,duration=0.5)
user_said_person_name=r.listen(source2)
person_name=r.recognize_google(user_said_person_name)
person_name=person_name.lower()
except sr.UnknownValueError():
print("Error")
dir=str(person_name)
pare="C:/Users/Asus/OneDrive/Desktop/juju/smrt goggles/codes/using web cam/database/"
path=os.path.join(pare,dir)
os.mkdir(path)
print("Directory '% s' created" %dir) #folder created
#to record face samples
cap = cv2.VideoCapture(0)
i = 1
os.chdir(path)
while(i<31):
ret, frame = cap.read()
if ret == False:
break
# Save Frame by Frame into specified path using imwrite method and name file like juju(1).jpg
cv2.imwrite(dir+str(i)+'.jpg', frame)
i += 1
cap.release()
cv2.destroyAllWindows()
print('_|-- Person added --|_')
#cutt
if face_status=='unknown':
savecmd()