免费 Node.js API 用于识别并提取图像中的文本
免费 Node.js 是领先的 Node.js API,提供多语言、多种字体和布局的高精度文本识别。
在当今以 AI 为驱动的开发世界中,光学字符识别(OCR)已成为自动从图像和文档中提取文本的关键技术。希望在 Node.js 中创建 OCR 的开发者可以从 Baidu-OCR-API 中受益匪浅,这是一款强大的工具,支持从图像中提取文本、手写文本识别,甚至在 Node.js 应用中进行表单识别等高级任务。无论是扫描发票、数字化文档,还是实现可访问性功能,这个 Node.js OCR 库都提供高性能,并且易于与现代应用集成。
Baidu-OCR-API 是免费 Node.js OCR API,利用深度学习识别多语言的印刷体和手写文本,包括中文、英文、日文等。它在 Node.js 中的表格识别、商务文档扫描以及在低光或失真图像等复杂环境下的文本识别方面表现出色。开发者还可以识别自然场景中的文本,使其非常适合移动应用、增强现实和实时翻译等使用场景。凭借其精准的识别能力和多样的应用场景,Baidu-OCR-API 是任何希望在 Node.js 应用中集成可靠 OCR 功能的开发者的理想选择。
开始使用 Baidu-OCR-API
推荐的安装 Baidu-OCR-API 的方式是使用 npm。请使用以下命令进行顺利安装
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.
在 Node.js 应用中从图像提取文本
Baidu-OCR-API 让软件开发者能够轻松加载和读取图像,并在 Node.js 应用中提取文本。通用文本识别功能允许开发者加载并提取图像中的印刷文本,适用于各种文档。该 API 已支持多种常见图像文件格式,如 JPEG、PNG、GIF、TIFF、PDF、BMP 等。以下示例展示了软件开发者如何在 Node.js 应用中加载图像并执行文本识别。
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);
});
在 Node.js 应用中进行表单和表格识别
开源的 Baidu-OCR-API 为 Node.js 应用提供了完整的表单和表格识别功能。要成功完成此任务,首先需要使用您的 API 凭证设置 Baidu OCR 客户端。然后,编写代码读取图像并执行表单和表格识别。此功能对于自动从结构化文档中提取数据并提升各种应用的生产力特别有用。下面是一个简单示例,展示软件开发者如何在 Node.js 环境中读取图像并进行表单和表格识别。
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);
});
通过 Node.js API 进行手写文本识别
开源的 Baidu-OCR-API 使用非常简便,能够在 Node.js 应用中高精度地识别手写文本。实现该目标的步骤是读取图像文件并将其转换为 base64 字符串,然后调用 handwriting 方法并传入该 base64 编码的图像,识别出的手写文本将记录到控制台。以下示例演示了软件开发者如何在 Node.js 中使用开源的 Baidu OCR API 进行手写文本识别。
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