How to Detect Fine Text in a Photo of a Document using Node.js

Cloudmersive
2 min readNov 27, 2023

--

It’s increasingly common for our file processing applications to handle images of documents in common image formats (like JPG or PNG, for example). When those document images contain fine text, we can use simple API solutions to single out the fine text and report its location to avoid accidentally cropping it out.

Using the below code, we can take advantage of a free API designed to report the location and size of fine text within a photo of a document. This will return the exact pixel coordinates of each fine text object identified within the image, including details like the height and angle of the text object.

To use this API for free, we’ll just need a free-tier Cloudmersive API key. These allow a limit of 800 API calls per month with no commitment.

We can easily structure our API call in a few quick steps. We can start by installing the SDK — either by running the below command:

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

Or by adding this snippet to our package.json:

  "dependencies": {
"cloudmersive-image-api-client": "^1.3.4"
}

With installation out of the way, we can use the below code to structure our request:

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.recognizeDetectTextFine(imageFile, callback);

Now we can easily call out fine text in document photos with a quick in-memory operation.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet