免费 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。请使用以下命令进行顺利安装
在 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 编码的图像,识别出的手写文本会输出到控制台。以下示例演示了软件开发者如何使用开源 Baidu OCR API 在 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