Skip to content

Commit

Permalink
complete image-analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
mwee committed Feb 24, 2017
1 parent d8b8751 commit f60109b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 54 deletions.
64 changes: 10 additions & 54 deletions lib/image-analysis.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,45 +259,13 @@ var amazonImageAnalysisAPIPack = function(apiInfo, packType) {
if (image != undefined && image.dataURI != undefined) {

baseAPIResponse.inputDataPresent = "true";
// baseAPIResponse.image = image;

//global credentials from http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/global-config-object.html
console.log("Setting amazon global keys");
var myCredentials = new AWS.CognitoIdentityCredentials({IdentityPoolId:'us-west-2_bcGMjsUWF'});
console.log("Amazon global key created");
var myConfig = new AWS.Config({
credentials: myCredentials, region: 'us-west-2'
});
console.log("Amazon global Config created");

serverPack.amazonConfig = {
region: 'us-west-2',
credentials: myCredentials
};
//we use process env variables with 'amazon supported' names per http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/setting-credentials-node.html
/*
The SDK automatically detects AWS credentials set as variables in your environment and uses them for SDK requests, eliminating the need to manage credentials in your application. The environment variables that you set to provide your credentials are:

AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_SESSION_TOKEN (optional)
*/

// var vision = serverPack.gcloud.vision();
console.log("creating AWS JS Rekognition object");
var rek = new AWS.Rekognition({region: 'us-west-2'});
var rek = new AWS.Rekognition({region: 'us-west-2'});
serverPack.rek = rek;

// console.log(image)
serverPack.amazonParameters = {
// language: language,
image: image
// config: config
};
console.log("done with config");

///serverPack.visionClient = vision;

serverPack.setReady(true);
} else {
Expand All @@ -308,23 +276,15 @@ console.log("done with config");

entitypack.setAPIFunctionExecute(function(serverPack, apiResponse, completion) {

var buffer = NXIMage.bufferFromJsonImage(serverPack.amazonParameters.image);

// var config = serverPack.gcloudParameters.config;
console.log("creating image buffer");
var buffer = NXIMage.bufferFromJsonImage(serverPack.amazonParameters.image);
console.log("image buffer created");

// http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Rekognition.html#detectLabels-property
var params = {
Image: {
Bytes: buffer
},
MaxLabels: 100,
MinConfidence: 0.0
};
console.log(buffer)

console.log("calling amazon API");
var params = {
Image: {
Bytes: buffer
},
MaxLabels: 100,
MinConfidence: 0.0
};

serverPack.rek.detectLabels(params, function(err, data) {
var renderText = "";
Expand All @@ -333,13 +293,10 @@ console.log("calling amazon API");
console.log("Image processing error."+err);
renderText += "<h1>Cloud Vision Error</h1>";
console.log('error:', err);
// apiResponse.result.score = -1;
resultObject = err;
}
else {
console.log("response ok:");
console.log(data);
apiResponse.result.score = ((data.Labels == undefined) ? 0 : data.Labels.length);
apiResponse.result.score = ((data.Labels == undefined) ? 0 : data.Labels.length);
resultObject = data;
}

Expand All @@ -349,7 +306,6 @@ console.log(data);

});


});

return entitypack;
Expand Down
10 changes: 10 additions & 0 deletions public/data/services/apis/amazon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"id" : "amazon-ai",
"provider": "Amazon",
"name": "Amazon AI",
"providerUrl": "https://aws.amazon.com/",
"consoleUrl": "https://console.aws.amazon.com/",
"officialGithubURL": "https://github.com/aws/aws-sdk-js",
"unofficialGithubURL": "",
"description": "AWS offers a family of AI services that provide cloud-native machine learning and deep learning technologies to address your different use cases and needs."
}

0 comments on commit f60109b

Please sign in to comment.