-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
145 lines (112 loc) · 4.23 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
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Eye for you main program
import keyboard
import cv2
import time
import argparse
import logging
import pyttsx3
import sys
saying = 1
logger = logging.getLogger('Eye For You Webcam')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('[%(asctime)s] [%(name)s] [%(levelname)s] %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
sys.path.append('\ocr')
sys.path.append('\yolo')
from yolo_lib import yolo as yl
from ocr import text_recognition
############## Text Recognition ################
def Read_Text(image):
return (image, [])
################################################
############## Obstacle Recognition ############
def Obstacle_Recognition(image):
return (image, [])
################################################
############## Face Recognition ################
def Face_Recognition(image):
return (image, [])
def Do_Nothing(image):
return (image, [])
################################################
def say(text, language, ch_mode):
'''engine = pyttsx3.init()
engine.say("Object Recognized " + text)
a=engine.runAndWait()'''
engine = pyttsx3.init()
rate = engine.getProperty('rate')
engine.setProperty('rate', rate)
voices = engine.getProperty('voices')
en_voice_id = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0"
dictio = {'fr' : voices[0] , 'eng' : en_voice_id}
# for voice in voices:
voice_id = dictio[language]
engine.setProperty('voice', voice_id)
# print voice.id
#engine.say('Object Recognized' + text)
engine.say(ch_mode + text)
a = engine.runAndWait() # blocks
if __name__ == '__main__':
# All the args argument:
parser = argparse.ArgumentParser(description='Main-Code')
# parser.add_argument('--video', type=str, default='')
parser.add_argument('--camera', type=int, default=0)
parser.add_argument('--saying', type=int, default=0, help='Save in a video format')
parser.add_argument('--resolution', type=str, default='432x368', help='network input resolution. default=432x368')
parser.add_argument('--save_video', type=str, default='', help='Save in a video format')
args = parser.parse_args()
# cap = cv2.VideoCapture(args.video)
cam = cv2.VideoCapture(args.camera)
if args.save_video != '':
print('Saving the frames at %s' % args.save)
fps_time = 0
ret_val, image = cam.read()
logger.info('cam image=%dx%d' % (image.shape[1], image.shape[0]))
frames_counter = 1
# Default Mode
Mode = 'Do Nothing'
while True:
# Capturing the frame:
ret_val, image = cam.read()
language = "eng"
ch_mode = ""
################### Inputs #####################
if keyboard.is_pressed('a'):
Mode = 'Read Text'
language = 'fr'
ch_mode ='Text recognized'
elif keyboard.is_pressed('z'):
Mode = 'Obstacle Recognition'
language = 'eng'
ch_mode = 'Object recognized'
saying = True
elif keyboard.is_pressed('e'):
Mode = 'Face Recognition'
elif keyboard.is_pressed('r'):
Mode = 'Do Nothing'
elif keyboard.is_pressed('t'):
Mode = 'Obstacle Recognition'
saying = True
Functions = {'Read Text': text_recognition.ocr, 'Obstacle Recognition': yl.yolo, 'Face Recognition': Face_Recognition,
'Do Nothing': Do_Nothing}
if frames_counter % 3 == 0:
output, text = Functions[Mode](image)
try :
cv2.putText(output, "FPS: %f Mode Detection : %s" % ((1.0 / (time.time() - fps_time)), Mode), (10, 10),
cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
cv2.imshow('computation result', output)
except :
pass
if saying:
say(str(text) , language, ch_mode)
frames_counter += 1
if cv2.waitKey(1) & 0xFF == ord('q'):
break
fps_time = time.time()
cv2.destroyAllWindows()
################################################
################### Outputs ####################
################################################