-
Notifications
You must be signed in to change notification settings - Fork 2
/
images2.py
130 lines (90 loc) · 2.37 KB
/
images2.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
import requests
import json
from gtts import gTTS
import os
from BeautifulSoup import BeautifulSoup
import urllib2
import re
from py_edamam import Edamam
import time
initial_time = time.time()
flag = 0
def getRecipeByIngredients(ingredients):
try:
from googlesearch import search
except ImportError:
print("No module named 'google' found")
query = "edamam"
for x in ingredients:
query = query + " " + x
query = query + " site:www.edamam.com"
for j in search(query, tld="co.in", num=5, stop=5, pause=2):
soup = BeautifulSoup(urllib2.urlopen(j))
print soup.title.string
def produce_sound():
global flag
global initial_time
if(flag == 1):
return
new_time = time.time()
diff = new_time-initial_time
if(diff <= 15):
return
initial_time = time.time()
print("ALERT")
mytext = 'Hello Infosyians, welcome to Hack With Infy'
language = 'en'
myobj = gTTS(text=mytext, lang=language, slow=False)
myobj.save("welcome.mp3")
os.system("mpg321 welcome.mp3")
flag = 1
def objectify(file_name):
r = requests.post(
"https://api.deepai.org/api/densecap",
files={
'image': open(file_name, 'rb'),
},
headers={'api-key': '8e634a28-01e5-45f4-9793-ea4971769e42'}
)
x = r.json()
t_dict = {}
t_dict['banana'] = 1
t_dict['pineapple'] = 1
t_dict['capsicum'] = 1
t_dict['brinjal'] = 1
t_dict['bottle'] = 1
t_dict['apple'] = 1
y = x['output']
z = y['captions']
listt = []
for i in z:
for words in i['caption'].split():
if(str(words) in t_dict.keys()):
listt.append(str(words))
listt = list(dict.fromkeys(listt))
return listt
import cv2
import numpy as np
import signal
cam = cv2.VideoCapture(1)
cv2.namedWindow("test")
cv2.moveWindow("test",550,400)
img_counter = 0
while True:
ret, frame = cam.read()
cv2.imshow("test", frame)
if not ret:
break
k = cv2.waitKey(1)
x = np.amin(np.array(frame))
y = np.amax(np.array(frame))
if(y >= 180):
produce_sound()
else:
flag = 0
if k%256 == 27:
# ESC pressed
print("Escape hit, closing...")
break
cam.release()
cv2.destroyAllWindows()