-
Notifications
You must be signed in to change notification settings - Fork 1
/
vision.js
42 lines (37 loc) · 1.21 KB
/
vision.js
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
export default class Vision {
constructor (base64Image) {
this.image = base64Image,
this.apiKey = "https://vision.googleapis.com/v1/images:annotate?key=" + 'AIzaSyAISbg6ujMBUkFhb1CP6451dsaxTHMM7Gk'
}
async cloudVision() {
let results = []
const res = await fetch(this.apiKey, {
method: "POST",
body: JSON.stringify({
"requests":[
{
"image":{
"content": this.image
},
"features":[
{
"type":"LABEL_DETECTION",
"maxResults": 10
},
{
"type": "LOGO_DETECTION"
}
]
}
]
})
});
const data = await res.json()
for (let annotations in data.responses[0]) {
for (let prop of data.responses[0][annotations]) {
results.push(prop.description.toLowerCase())
}
}
return results
}
}