-
Notifications
You must be signed in to change notification settings - Fork 0
/
brain.py
57 lines (49 loc) · 2.06 KB
/
brain.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
from random import randrange
import cv2
import image_detection_yolo as yolo
import text_to_speech
from PIL import Image, ImageDraw, ImageFont
from text_caption import getImageCaption
from text_read import get_string_from_img
sentences = [
"There is a {} in front of you",
"I see {}"
]
def brain(data, model, classes, colors, output_layers):
image = cv2.imread('current.png')
if data and ("hi" in data or "what is this" in data or "what is" in data or "do you see" in data):
text_to_speech.SpeakText("Let me see")
print("before imge_process")
statement = image_process(image, model, classes, colors, output_layers)
text_to_speech.SpeakText(statement)
elif data and ("describe" in data or "descibe surrounding" in data):
text_to_speech.SpeakText("Let me see")
#Here let's integrate the desctibe call
res = getImageCaption("./current.png")
if not res:
text_to_speech.SpeakText("Sorry there is no text to read")
else:
text_to_speech.SpeakText(res)
elif data and ("read it" in data or "please read" in data):
text_to_speech.SpeakText("Let me see")
res = get_string_from_img("./current.png")
if not res:
text_to_speech.SpeakText("Sorry there is no text to read")
else:
text_to_speech.SpeakText(res)
else:
text_to_speech.SpeakText("Sorry! I don't understand")
def image_process(frame, model, classes, colors, output_layers):
height, width, channels = frame.shape
blob, outputs = yolo.detect_objects(frame, model, output_layers)
boxes, confs, class_ids = yolo.get_box_dimensions(outputs, height, width)
print("*** confs:{} {} ".format(max(confs), classes[class_ids[confs.index(max(confs))]]))
print("***8 class_ids: ",class_ids)
#print_labels(classes,class_ids)
objs = []
for id in range(len(confs)):
objs.append(classes[class_ids[id]])
i = randrange(0, len(sentences))
if len(objs) > 1:
objs.insert(-2, "and")
return sentences[i].format(" ".join(objs))