-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
162 lines (133 loc) · 5.18 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
146
147
148
149
150
151
152
153
154
155
156
157
158
"""
import subprocess
from google.cloud import vision
import io
import time
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(4)
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__":
labelfunc()
ocrfunc()
"""
import subprocess
from google.cloud import vision
import io
import time
from gtts import gTTS
import os
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
#print(texts)
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(4)
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 + " thank 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"])
labelfunc()
ocrfunc()