How to Generate Automatic Description of an Image using Node.js

Sometimes, the best captions are the obvious ones: an exact description of what the photo contains. Using machine learning, our Image Description API automatically recognizes the contents within an image and generates two plain text descriptions of what lies within it. Those different descriptions include a “BestOutcome” and a “RunnerUpOutcome,” and each of those outcomes receives an attached “ConfidenceScore” indicating the degree to which the API believes it’s analysis was successful. Please refer to the below response model:

{
"Successful": true,
"Highconfidence": true,
"BestOutcome": {
"ConfidenceScore": 0,
"Description": "string"
},
"RunnerUpOutcome": {
"ConfidenceScore": 0,
"Description": "string"
}
}

Below, we’ll demonstrate how you can take advantage of this API with Node.js by structuring your API call with the code examples provided below.

First, let’s install the SDK using the following command:

npm install cloudmersive-image-api-client --save

Next, let’s call the function using the below code block. At the top, you can input your Cloudmersive API key for authentication (obtainable by registering a free account on our website):

var CloudmersiveImageApiClient = require('cloudmersive-image-api-client');
var defaultClient = CloudmersiveImageApiClient.ApiClient.instance;
// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';
var apiInstance = new CloudmersiveImageApiClient.RecognizeApi();var imageFile = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // File | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.recognizeDescribe(imageFile, callback);

With that, you’re all set — no more coding required.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Cloudmersive

Cloudmersive

437 Followers

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.