node-red-contrib-cognitive-services
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -22,3 +22,3 @@ var request = require('request'); | ||
options = { | ||
url: 'https://api.projectoxford.ai/vision/v1.0/analyze', | ||
url: 'https://api.projectoxford.ai/vision/v1.0/analyze?visualFeatures=Categories,Tags,Description,Faces,ImageType,Color,Adult', | ||
method: 'POST', | ||
@@ -35,3 +35,3 @@ headers: { | ||
options = { | ||
url: 'https://api.projectoxford.ai/vision/v1.0/analyze', | ||
url: 'https://api.projectoxford.ai/vision/v1.0/analyze?visualFeatures=Categories,Tags,Description,Faces,ImageType,Color,Adult', | ||
method: 'POST', | ||
@@ -61,15 +61,82 @@ headers: { | ||
{ | ||
if (body.categories.length > 0 && body.categories[0].name != null) | ||
if (config.operation == "tags") // Tags | ||
{ | ||
var tmp = body.categories.sort(function(a, b) { | ||
return b.score - a.score; | ||
}); | ||
msg.payload = tmp[0].name; | ||
if (body.tags.length > 0 && body.categories[0].name != null) | ||
{ | ||
var tmp = body.tags.sort(function(a, b) { | ||
return b.confidence - a.confidence; | ||
}); | ||
var array = []; | ||
for (var i = 0; i < tmp.length; i++) | ||
{ | ||
array.push(tmp[i].name); | ||
} | ||
msg.payload = array; | ||
} | ||
else | ||
{ | ||
msg.payload = null; | ||
} | ||
msg.detail = body; | ||
node.send(msg); | ||
} | ||
else if (config.operation == "description") // Description | ||
{ | ||
if (body != null && body.description != null && body.description.captions != null && body.description.captions.length > 0) | ||
{ | ||
var tmp = body.description.captions.sort(function(a, b) { | ||
return b.confidence - a.confidence; | ||
}); | ||
msg.payload = tmp[0].text; | ||
} | ||
else | ||
{ | ||
msg.payload = null; | ||
} | ||
msg.detail = body; | ||
node.send(msg); | ||
} | ||
else if (config.operation == "age") // Faces(age) | ||
{ | ||
if (body.faces != null && body.faces.length > 0 && body.faces[0].age != null) | ||
{ | ||
msg.payload = body.faces[0].age; | ||
} | ||
else | ||
{ | ||
msg.payload = null; | ||
} | ||
msg.detail = body; | ||
node.send(msg); | ||
} | ||
else if (config.operation == "gender") // Faces(gender) | ||
{ | ||
if (body.faces != null && body.faces.length > 0 && body.faces[0].gender != null) | ||
{ | ||
msg.payload = body.faces[0].gender; | ||
} | ||
else | ||
{ | ||
msg.payload = null; | ||
} | ||
msg.detail = body; | ||
node.send(msg); | ||
} | ||
else if (config.operation == "adult") // Adult | ||
{ | ||
if (body.adult != null && body.adult.adultScore != null) | ||
{ | ||
msg.payload = Math.round(body.adult.adultScore * Math.pow(10, 2)) / Math.pow(10, 2);; | ||
} | ||
else | ||
{ | ||
msg.payload = null; | ||
} | ||
msg.detail = body; | ||
node.send(msg); | ||
} | ||
else | ||
{ | ||
msg.payload = null; | ||
node.error("Unsupported operation: " + config.operation); | ||
} | ||
msg.detail = body; | ||
node.send(msg); | ||
} | ||
@@ -76,0 +143,0 @@ else |
{ | ||
"name": "node-red-contrib-cognitive-services", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Microsoft Cognitive Services", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
95513
1034