-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathcomputerVision.py
More file actions
32 lines (28 loc) · 899 Bytes
/
computerVision.py
File metadata and controls
32 lines (28 loc) · 899 Bytes
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
import http.client, urllib.request, urllib.parse, urllib.error, base64
filename = None
headers = {
# Request headers
'Content-Type': 'application/octet-stream',
'Ocp-Apim-Subscription-Key': '54ea2eeb4e804346bb5f5017c3e298b5',
}
params = urllib.parse.urlencode({
# Request parameters
'visualFeatures': 'Tags',
'language': 'en',
})
def runCV():
with open(filename, 'rb') as f:
img_data = f.read()
conn = http.client.HTTPSConnection('eastasia.api.cognitive.microsoft.com')
conn.request("POST", "/vision/v2.0/analyze?%s" % params, img_data, headers)
response = conn.getresponse()
data = response.read()
result = False
import json
data_1 = (json.loads(data)['tags'])
for i in data_1:
if 'ambulance' == i['name']:
result = True
break
conn.close()
return result