How to Describe an Image in Natural Language using JavaScript

Cloudmersive
2 min readMay 31, 2022

--

“A group of people sitting around a table” (Description generated with NLP Image Description API)

Describing a basic image might be easy, but it also takes up valuable time. If your app needs hundreds of new photos, does it really make sense to caption them all by hand? Our NLP Image Description API lets you cut a corner by leveraging machine learning to describe new images automatically. Two descriptions will be provided for each image, and a confidence score will be provided for each of those to define how likely it is that the descriptions are accurate.

*Sample Response Model*{
"Successful": true,
"Highconfidence": true,
"BestOutcome": {
"ConfidenceScore": 0,
"Description": "string"
},
"RunnerUpOutcome": {
"ConfidenceScore": 0,
"Description": "string"
}
}

Interested in incorporating this API into your app? That’s easy — just follow instructions below to structure your API call with JavaScript. We’ve provided ready-to-run code for the occasion, so all you need to do is copy & paste, then register a free Cloudmersive account on our website to get your API key, and you’re all set.

Let’s begin by installing jQuery. Run the below command:

bower install jquery

Now let’s call the API. To do that, let’s first use the below snippet to capture the image file:

var form = new FormData();
form.append("imageFile", fileInput.files[0], "file");

Then let’s include the remaining code, including our API key on line 7 (“YOUR-API-KEY-HERE”):

var settings = {
"url": "https://api.cloudmersive.com/image/recognize/describe",
"method": "POST",
"timeout": 0,
"headers": {
"Content-Type": "multipart/form-data",
"Apikey": "YOUR-API-KEY-HERE"
},
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};
$.ajax(settings).done(function (response) {
console.log(response);
});

All done. Yep — it’s really that easy. With your Cloudmersive API key, you’ll also have access to dozens of additional Cloudmersive utility APIs which you can review by visiting our API page. Enjoy!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet