-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogle.js
More file actions
69 lines (56 loc) · 1.78 KB
/
google.js
File metadata and controls
69 lines (56 loc) · 1.78 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
//LABEL, FACE, TEXT, DOCUMENT_TEXT
module.exports.googleVision = function(imageUrl, features, callback){
console.log("Before GOOGLE VISION request.");
var googleFeatures = [];
for (var i = 0; i < features.length; i++) {
var feature = {
"type": features[i].toUpperCase()+ "_DETECTION"
}
googleFeatures.push(feature);
}
//Parámetros para el Request de Cloud Vision
var parameters = {
"requests": [
{
"features": googleFeatures,
"image": {
"source": {
"imageUri": imageUrl
}
}
}
]
}
var params = JSON.stringify(parameters);
Parse.Cloud.httpRequest({
method: 'POST',
url: "https://vision.googleapis.com/v1/images:annotate?key=AIzaSyBL0QYPScnrjHML8i9Kq5VLXVuqoiM_34o",
body: params
}).then(function(httpResponse) {
console.log("Google Responded");
var resp = JSON.parse(httpResponse.text);
var labelAnnotations = resp.responses[0].labelAnnotations;
var faces = resp.responses[0].faceAnnotations;
var labels = [];
for (var i = 0; i < labelAnnotations.length; i++) {
labels.push(labelAnnotations[i].description);
}
var fullTextAnnotation = resp.responses[0].fullTextAnnotation;
var textAnnotations = resp.responses[0].textAnnotations;
if(fullTextAnnotation != undefined){
var fullText = fullTextAnnotation.text;
console.log('FullText: ' + fullText);
}
console.log("Labels: " + labels.toString());
// Respuesta modificada
var googleResponse = {
"labels":labels,
"fullText":fullText,
"textAnnotations":textAnnotations
};
if(faces != undefined){
googleResponse.faces = faces.length
}
callback(null,googleResponse);
});
}