@fnet/ocr-text-coords (英语)
这个项目旨在利用 " Testeract.js " 库,便利从图像中取出文本及其相应的边框坐标。 它支持各种输入格式,例如文件路径,URL,或Base64编码字符串,并且可以处理多种语言.
如何运作
该项目使用Testeract.js在特定图像上进行光学字符识别(OCR). 您通过文件路径, URL, 或 Base64 字符串, 以及语言规格提供图像 。 工程然后处理图像,识别文本并用边框标出每个单词的位置. 此信息作为一个结构化对象返回,其中既包含已取出的案文,也包含坐标.
关键特性
- 文本提取: 自动从图像中提取文本.
- 边框坐标:提供每个被检测到的单词的坐标.
- 多个输入格式:工作有文件路径,URL,或 Base64 图像数据.
- 语言支持:通过指定语言代码,允许多种语言的识别.
结论
这个项目为在图像中提取和定位文本提供了一个直接的方法,适用于各种格式和语言。 它为访问Testeract.js能力提供了一个简单的接口,返回结构化的结果,这些结果可以容易地被融入到进一步的处理或分析任务中去.
@fnet/ocr-text-coords 开发者指南
概览
这个 @fnet/ocr-text-coords 库旨在帮助开发者从图像中提取文本内容及其边框坐标。 使用由Testeract.js提供动力的光学字符识别(OCR),这个库支持通过文件路径,URL,或 Base64字符串提供的图像. 开发者可以轻松地将这个功能整合到需要从视觉媒体取出文本的应用程序中.
安装
你可以安装 @fnet/ocr-text-coords 使用 npm 或纱线的库 :
npm install @fnet/ocr-text-coords
或用纱线:
yarn add @fnet/ocr-text-coords
使用量
库提供了一个简单的公共功能,您可以用来从图像中提取文本 :
基本用途
首先,将库导入到您的项目中 :
import extractTextWithCoords from '@fnet/ocr-text-coords';
然后可以使用该函数处理图像 :
(async () => {
try {
const result = await extractTextWithCoords({ imageInput: 'path/to/your/image.jpg', language: 'eng' });
console.log(result.text); // Outputs full extracted text
console.log(result.words); // Outputs array of words with bounding boxes
} catch (error) {
console.error('Error extracting text:', error.message);
}
})();
参数
imageInput:代表图像输入的字符串。 这可以是文件路径,URL,也可以是Base64编码字符串.language(可选):指定OCR语言的字符串. 默认是"eng"。可以通过加号加入多种语言的代码(例如,"eng+tur") (中文(简体) ).
实例
以下是一些实例,说明典型的使用案例:
从本地文件取出文本
import extractTextWithCoords from '@fnet/ocr-text-coords';
// Process an image from a local file
(async () => {
const result = await extractTextWithCoords({ imageInput: './local-image.png' });
console.log(result);
})();
从 URL 中提取文本
import extractTextWithCoords from '@fnet/ocr-text-coords';
// Process an image from a URL
(async () => {
const result = await extractTextWithCoords({ imageInput: 'https://example.com/image.jpg', language: 'eng+spa' });
console.log(result);
})();
从 Base64 字符串中提取文本
import extractTextWithCoords from '@fnet/ocr-text-coords';
// Process an image from a Base64 string
(async () => {
const base64String = 'data:image/png;base64,iVBORw0KGgoAAAANS...';
const result = await extractTextWithCoords({ imageInput: base64String });
console.log(result);
})();
致谢
这个库使用Testeract.js进行OCR处理. Testeract.js是一款由活跃的开发者社区所支持的开源OCR引擎.
输入外观
$schema: https://json-schema.org/draft/2020-12/schema
type: object
properties:
imageInput:
type: string
description: The path, URL, or Base64 string of the image to be processed.
language:
type: string
description: The language code(s) to use for OCR (e.g., "eng", "tur", or "eng+tur").
default: eng
required:
- imageInput