-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempCodeRunnerFile.py
More file actions
73 lines (51 loc) · 1.75 KB
/
tempCodeRunnerFile.py
File metadata and controls
73 lines (51 loc) · 1.75 KB
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
# pip install opencv-contrib-python # some people ask the difference between this and opencv-python
# and opencv-python contains the main packages wheras the other
# contains both main modules and contrib/extra modules
# pip install cvlib # for object detection
# # pip install gtts
# # pip install playsound
# use `pip3 install PyObjC` if you want playsound to run more efficiently.
import cv2
import cvlib as cv
from cvlib.object_detection import draw_bbox
from gtts import gTTS
from food_facts import food_facts
def speech(text):
print(text)
language = "en"
output = gTTS(text=text, lang=language, slow=False)
output.save("./sounds/output.mp3")
playsound("./sounds/output.mp3")
video = cv2.VideoCapture(1)
labels = []
while True:
ret, frame = video.read()
# Bounding box.
# the cvlib library has learned some basic objects using object learning
# usually it takes around 800 images for it to learn what a phone is.
bbox, label, conf = cv.detect_common_objects(frame)
output_image = draw_bbox(frame, bbox, label, conf)
cv2.imshow("Detection", output_image)
for item in label:
if item in labels:
pass
else:
labels.append(item)
if cv2.waitKey(1) & 0xFF == ord("q"):
break
i = 0
new_sentence = []
for label in labels:
if i == 0:
new_sentence.append(f"I found a {label}, and, ")
else:
new_sentence.append(f"a {label},")
i += 1
speech(" ".join(new_sentence))
speech("Here are the food facts i found for these items:")
for label in labels:
try:
print(f"\n\t{label.title()}")
food_facts(label)
except:
print("No food facts for this item")