1. Products
  2.   OCR
  3.   Node.js
  4.   Baidu-ocr-api
 
  

Free Node.js API to Recognize & Extract Text from Images

A Free Node.js is a Leading Node.js API that Offers High Accuracy in Text Recognition Across Multiple Languages and a Variety of Fonts and Layouts.

In today’s AI-driven development world, Optical Character Recognition (OCR) has become essential for automating text extraction from images and documents. Developers seeking to create OCR in Node.js can benefit greatly from the Baidu-OCR-API, a powerful tool that supports extracting text from images, handwriting text recognition, and even advanced tasks like form recognition inside Node.js apps. Whether it's scanning invoices, digitizing documents, or enabling accessibility features, this Node.js OCR library offers high performance and is easy to integrate with modern applications.

Baidu-OCR-API is a free Node.js OCR API that utilizes deep learning to recognize printed and handwritten text across multiple languages, including Chinese, English, Japanese, and more. It excels in table recognition in Node.js, business document scanning, and recognizing text in complex conditions such as low-light or distorted images. Developers can also recognize text within natural scenes, making it perfect for mobile apps, augmented reality, and real-time translation use cases. With its accurate recognition and versatile use cases, Baidu-OCR-API is an ideal choice for any developer looking to integrate reliable OCR functionality into Node.js applications.

Previous Next

Getting Started with Baidu-OCR-API

The recommend way to install Baidu-OCR-API is using npm. Please use the following command for a smooth installation

Install Baidu-OCR-APIvia npm

 npm install baidu-ocr-api -g 

You can also install it manually; download the latest release files directly from GitHub repository.

Extract Text from Images inside Node.js Apps

Baidu-OCR-API makes it easy for software developers to load and read images and extract text inside Node.js applications. The general text recognition feature allows developers to load and extract printed text from images, suitable for a wide range of documents. The API has included support various popular image file formats, such as JPEG, PNG, GIF, TIFF, PDF, BMP, and many more. The following example shows how software developers can load and perform text recognition on the image inside Node.js applications.

How to Load and Perform Text Recognition on an Image inside Node.js Apps?

//Read image

const fs = require('fs');

// Read the image file and convert it to base64
function readImage(filePath) {
    return fs.readFileSync(filePath, { encoding: 'base64' });
}

const image = readImage('path_to_your_image.jpg');

// Perform OCR
client.generalBasic(image).then(result => {
    console.log('Recognized Text:');
    result.words_result.forEach(wordInfo => {
        console.log(wordInfo.words);
    });
}).catch(err => {
    console.error(err);
});

Form and Table Recognition inside Node.js Apps

The open source Baidu-OCR-API has provided complete functionality for recognizing form and table inside Node.js applications. To perform the task successful first you need to set up your Baidu OCR client using your API credentials. Then, write the code to read an image and perform form and table recognition. This functionality can be particularly useful for automating data extraction from structured documents and enhancing productivity in various applications. Here is simple example that shows, how software developer can read an image and perform form and table recognition inside Node.js environment.

How to Read an Image and Perform Form and Table Recognition in Node.js Apps?

const BaiduOCR = require('baidu-ocr-api');
const fs = require('fs');

// Your API credentials
const APP_ID = 'your-app-id';
const API_KEY = 'your-api-key';
const SECRET_KEY = 'your-secret-key';

// Initialize the Baidu OCR client
const client = new BaiduOCR(APP_ID, API_KEY, SECRET_KEY);

// Function to read the image file and convert it to base64
function readImage(filePath) {
    return fs.readFileSync(filePath, { encoding: 'base64' });
}

// Path to your image
const image = readImage('path_to_your_image.jpg');

// Perform Form and Table Recognition
client.form(image).then(result => {
    console.log('Form and Table Data:');
    console.log(JSON.stringify(result, null, 2));
}).catch(err => {
    console.error('Error:', err);
});

Handwriting Text Recognition via Node.js API

The open source Baidu-OCR-API is very easy to handle and is fully capable of recognizing handwritten text with high precision inside Node.js applications. The achieve the goal the image file is read and converted to a base64 string and after that The handwriting method is called with the base64-encoded image, and the recognized handwritten text is logged to the console. The following example demonstrates how software developers can perform handwriting text recognition using the open-source Baidu OCR API in Node.js.

How to Perform Handwriting Text Recognition inside Node.js Apps?

// Path to your image
const image = readImage('path_to_your_image.jpg');

// Perform Handwriting Text Recognition
client.handwriting(image).then(result => {
    console.log('Recognized Handwritten Text:');
    result.words_result.forEach(wordInfo => {
        console.log(word