-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathedit.py
356 lines (304 loc) · 12.1 KB
/
edit.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
"""
#The same procedure is written in different ways with upgrades
#so you can refer all of them
import subprocess
from google.cloud import vision
import io
import time
import RPi.GPIO as GPIO
GPIO.setmode( GPIO.BCM)
GPIO.setup(20,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(21,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(19,GPIO.IN,pull_up_down=GPIO.PUD_UP)
imagePath = "/home/pi/Desktop/netra/images/"
image = imagePath + "capture.jpg"
image1 = imagePath + "capture1.jpg"
def detect_text(path):
#Detects text in the file
client = vision.ImageAnnotatorClient()
final = []
with io.open(path, 'rb') as image_file:
content = image_file.read()
image = vision.types.Image(content=content)
response = client.text_detection(image=image)
texts = response.text_annotations
for text in texts:
final.append(text.description.encode('utf-8'))
return final
def detect_labels(path):
# Detects labels in the file.
labelArray= []
client = vision.ImageAnnotatorClient()
with io.open(path, 'rb') as image_file:
content = image_file.read()
image = vision.types.Image(content=content)
response = client.label_detection(image=image)
labels = response.label_annotations
print('Labels:')
for label in labels:
val = label.description
labelArray.append(val.encode("utf-8"))
return labelArray
def labelfunc():
# TODO: Set a trigger event
#while True:
#if button1=="pressed":
# Button For Object Detection
subprocess.call(["fswebcam", "-r", "640x480", "--jpeg", "85", "-D", "1", image])
recognizedObjects = detect_labels(image)
str1 = ' '.join(recognizedObjects)
strFinal = "There are " + str1 + " infront of you"
print(str1)
subprocess.call(["gtts-cli", strFinal , "--output", "/home/pi/Desktop/hello.mp3"])
subprocess.call(["vlc", "--vout", "none", "/home/pi/Desktop/hello.mp3"])
# TODO: Pass this Above array in google text to speech code
#if button2 =="pressed":
# Execute OCR Script
def ocrfunc():
time.sleep(2)
subprocess.call(["fswebcam", "-r", "640x480", "--jpeg", "85", "-D", "1", image1])
ocrText = detect_text(image)
str2 = ''.join(ocrText)
strFinal2 = "There are " + str2 + " infront of you"
subprocess.call(["gtts-cli", strFinal2 , "--output", "/home/pi/Desktop/hello.mp3"])
subprocess.call(["vlc", "--vout", "none", "/home/pi/Desktop/hello.mp3"])
if __name__ == "__main__":
#while True:
#PushButton0 = GPIO.input(19)
while True:
PushButton1 = GPIO.input(20)
PushButton2 = GPIO.input(21)
if PushButton1 == False:
labelfunc()
PushButton1 = True
if PushButton2 == False:
ocrfunc()
PushButton2 = True
---------------------------------------------------------------------------------------------------------------------------
import subprocess
from google.cloud import vision
import io
import time
import RPi.GPIO as GPIO
from gtts import gTTS
import os
GPIO.setmode( GPIO.BCM)
GPIO.setup(20,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(21,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(19,GPIO.IN,pull_up_down=GPIO.PUD_UP)
imagePath = "/home/pi/Desktop/netra/images/"
image = imagePath + "capture.jpg"
image1 = imagePath + "capture1.jpg"
def detect_text(path):
# Detects text in the file.
client = vision.ImageAnnotatorClient()
final = []
with io.open(path, 'rb') as image_file:
content = image_file.read()
image = vision.types.Image(content=content)
response = client.text_detection(image=image)
texts = response.text_annotations
for text in texts:
final.append(text.description.encode('utf-8'))
return final
def detect_labels(path):
# Detects labels in the file.
labelArray= []
client = vision.ImageAnnotatorClient()
with io.open(path, 'rb') as image_file:
content = image_file.read()
image = vision.types.Image(content=content)
response = client.label_detection(image=image)
labels = response.label_annotations
print('Labels:')
for label in labels:
val = label.description
labelArray.append(val.encode("utf-8"))
return labelArray
def labelfunc():
# TODO: Set a trigger event
#while True:
#if button1=="pressed":
# Button For Object Detection
subprocess.call(["fswebcam", "-r", "640x480", "--jpeg", "85", "-D", "1", image])
recognizedObjects = detect_labels(image)
str1 = ' '.join(recognizedObjects)
#strFinal = "There are " + str1 + " infront of you"
print(str1)
#subprocess.call(["gtts-cli", strFinal , "--output", "/home/pi/Desktop/hello.mp3"])
#subprocess.call(["vlc", "--vout", "none", "/home/pi/Desktop/hello.mp3"])
myObj = gTTS ( text= "Things in front of you are " + str1 , lang = 'en', slow = False)
myObj.save("/home/pi/Desktop/netra/hello.mp3")
# os.system("mpg321 hello.mp3")
subprocess.call(["vlc", "--vout", "none", "/home/pi/Desktop/netra/hello.mp3"])
# TODO: Pass this Above array in google text to speech code
#if button2 =="pressed":
# Execute OCR Script
def ocrfunc():
#time.sleep(2)
subprocess.call(["fswebcam", "-r", "640x480", "--jpeg", "85", "-D", "1", image1])
ocrText = detect_text(image1)
str2 = ''.join(ocrText)
#strFinal2 = "There are " + str2 + " infront of you"
myObj = gTTS ( text= "The text written in front of you is " + str2 + " infront of you" , lang = 'en', slow = False)
myObj.save("/home/pi/Desktop/netra/hello.mp3")
# subprocess.call(["gtts-cli", strFinal2 , "--output", "/home/pi/Desktop/hello.mp3"])
subprocess.call(["vlc", "--vout", "none", "/home/pi/Desktop/netra/hello.mp3"])
if __name__ == "__main__":
myObj = gTTS ( text= "Welcome to netra by devtech" , lang = 'en', slow = False)
myObj.save("/home/pi/Desktop/netra/hello.mp3")
# os.system("mpg321 hello.mp3")
subprocess.call(["vlc", "--vout", "none", "/home/pi/Desktop/netra/hello.mp3"])
flag = False
while True:
PushButton0 = GPIO.input(19)
while PushButton0 == False:
print("YOU'RE ACTIVE")
PushButton1 = GPIO.input(20)
PushButton2 = GPIO.input(21)
if PushButton1 == False:
print("OBJECT DETECTION ACTIVE")
labelfunc()
while PushButton1 == False:
PushButton1 = GPIO.input(20)
PushButton0 = GPIO.input(19)
if PushButton0 == True:
flag = True
break
if PushButton2 == False:
print("OCR ACTIVE")
ocrfunc()
while True:
PushButton2 = GPIO.input(21)
if PushButton2 == True:
break
PushButton0 = GPIO.input(19)
if PushButton0 == True:
flag = True
break
if flag == True:
break
print("CONNECTION CLOSED!")
myObj = gTTS ( text= "Thanks for using netra by devtech" , lang = 'en', slow = False)
myObj.save("/home/pi/Desktop/netra/hello.mp3")
# os.system("mpg321 hello.mp3")
subprocess.call(["vlc", "--vout", "none", "/home/pi/Desktop/netra/hello.mp3"])
"""
import subprocess
from google.cloud import vision
import io
import time
import RPi.GPIO as GPIO
from gtts import gTTS
import os
GPIO.setmode( GPIO.BCM)
GPIO.setup(20,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(21,GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.setup(19,GPIO.IN,pull_up_down=GPIO.PUD_UP)
imagePath = "/home/pi/Desktop/netra/images/"
image = imagePath + "capture.jpg"
image1 = imagePath + "capture1.jpg"
def detect_text(path):
"""Detects text in the file."""
try:
client = vision.ImageAnnotatorClient()
final = []
with io.open(path, 'rb') as image_file:
content = image_file.read()
image = vision.types.Image(content=content)
response = client.text_detection(image=image)
texts = response.text_annotations
for text in texts:
final.append(text.description.encode('utf-8'))
return final
except:
return final
def detect_labels(path):
"""Detects labels in the file."""
labelArray= []
client = vision.ImageAnnotatorClient()
with io.open(path, 'rb') as image_file:
content = image_file.read()
image = vision.types.Image(content=content)
response = client.label_detection(image=image)
labels = response.label_annotations
print('Labels:')
for label in labels:
val = label.description
labelArray.append(val.encode("utf-8"))
return labelArray
def labelfunc():
"""TODO: Set a trigger event"""
#while True:
#if button1=="pressed":
"""Button For Object Detection"""
subprocess.call(["fswebcam", "-r", "640x480", "--no-banner", "--jpeg", "85", "-D", "1", image])
recognizedObjects = detect_labels(image)
str1 = ' '.join(recognizedObjects)
#strFinal = "There are " + str1 + " infront of you"
print(str1)
#subprocess.call(["gtts-cli", strFinal , "--output", "/home/pi/Desktop/hello.mp3"])
#subprocess.call(["vlc", "--vout", "none", "/home/pi/Desktop/hello.mp3"])
myObj = gTTS ( text= "Things in front of you are " + str1 + ", , " , lang = 'en', slow = False)
myObj.save("/home/pi/Desktop/netra/hello.mp3")
# os.system("mpg321 hello.mp3")
subprocess.call(["omxplayer", "--no-keys", "/home/pi/Desktop/netra/hello.mp3", " $ "])
"""TODO: Pass this Above array in google text to speech code"""
#if button2 =="pressed":
"""Execute OCR Script"""
def ocrfunc():
#time.sleep(2)
subprocess.call(["fswebcam", "-r", "640x480", "--no-banner", "--jpeg", "85", "-D", "1", image1])
ocrText = detect_text(image1)
str2 = ''.join(ocrText)
first_half=len(str2)
print(str2[0:first_half/2])
#strFinal2 = "There are " + str2 + " infront of you"
myObj = gTTS ( text= "The text written in front of you is " + str2[0:first_half/2] + ", , " , lang = 'en', slow = False)
try:
myObj.save("/home/pi/Desktop/netra/hello.mp3")
except:
myObj = gTTS ( text= "The text written in front of you is " + str2[0:(first_half/2)-5] + ", , " , lang = 'en', slow = False)
myObj.save("/home/pi/Desktop/netra/hello.mp3")
# subprocess.call(["gtts-cli", strFinal2 , "--output", "/home/pi/Desktop/hello.mp3"])
subprocess.call(["omxplayer", "--no-keys", "/home/pi/Desktop/netra/hello.mp3", " $ "])
if __name__ == "__main__":
#myObj = gTTS ( text= "Welcome to netra by devtech, press the top most key to enter the system, middle key for object detection, and, bottom key for text recognition, you're good to start now." , lang = 'en', slow = False)
#myObj.save("/home/pi/Desktop/netra/begin.mp3")
# os.system("mpg321 hello.mp3")
subprocess.call(["omxplayer", "--no-keys", "/home/pi/Desktop/netra/begin.mp3", " $ "])
flag = False
PushButton0 = True
while True:
PushButton0 = GPIO.input(19)
while PushButton0 == False:
print("YOU'RE ACTIVE")
PushButton1 = GPIO.input(20)
PushButton2 = GPIO.input(21)
if PushButton1 == False:
print("OBJECT DETECTION ACTIVE")
labelfunc()
while PushButton1 == False:
PushButton1 = GPIO.input(20)
PushButton0 = GPIO.input(19)
if PushButton0 == True:
flag = True
break
if PushButton2 == False:
print("OCR ACTIVE")
ocrfunc()
while True:
PushButton2 = GPIO.input(21)
if PushButton2 == True:
break
PushButton0 = GPIO.input(19)
if PushButton0 == True:
flag = True
break
if flag == True:
break
print("CONNECTION CLOSED!")
#myObj = gTTS ( text= "Thanks for using netra by Devtech, have a nice day." , lang = 'en', slow = False)
#myObj.save("/home/pi/Desktop/netra/credit.mp3")
# os.system("mpg321 hello.mp3")
subprocess.call(["omxplayer", "--no-keys", "/home/pi/Desktop/netra/credit.mp3", " $ "])