@fnet/ocr-text-coords

中文文档
0.1.1发布于 2024/11/09MITESM + CJS近 30 天下载 2.6万

This project is designed to facilitate the extraction of text and their corresponding bounding box coordinates from images, using the Tesseract.js library. It supports various input formats such as file paths, URLs, or Base64 encoded strings and can handl

原始使用文档
文档目录13 节
  1. How It Works
  2. Key Features
  3. Conclusion
  4. Overview
  5. Installation
  6. Usage
  7. Basic Usage
  8. Parameters
  9. Examples
  10. Extracting Text from a Local File
  11. Extracting Text from a URL
  12. Extracting Text from a Base64 String
  13. Acknowledgement

@fnet/ocr-text-coords

This project is designed to facilitate the extraction of text and their corresponding bounding box coordinates from images, using the Tesseract.js library. It supports various input formats such as file paths, URLs, or Base64 encoded strings and can handle multiple languages.

How It Works

The project uses Tesseract.js to perform Optical Character Recognition (OCR) on a given image. You provide an image through a file path, URL, or Base64 string, along with a language specification. The project then processes the image, identifying text and marking each word's location with a bounding box. This information is returned as a structured object containing both the extracted text and coordinates.

Key Features

  • Text Extraction: Automatically extracts text from images.
  • Bounding Box Coordinates: Provides the coordinates for each detected word.
  • Multiple Input Formats: Works with file paths, URLs, or Base64 image data.
  • Language Support: Allows recognition in multiple languages by specifying language codes.

Conclusion

This project offers a straightforward way to extract and locate text within images, applicable to a variety of formats and languages. It provides a simple interface to access Tesseract.js capabilities, returning structured results that can be easily integrated into further processing or analysis tasks.

Developer Guide for @fnet/ocr-text-coords

Overview

The @fnet/ocr-text-coords library is designed to help developers extract textual content from images along with their bounding box coordinates. Using Optical Character Recognition (OCR) powered by Tesseract.js, this library supports images provided via file paths, URLs, or Base64 strings. Developers can easily integrate this functionality into applications where text extraction from visual media is required.

Installation

You can install the @fnet/ocr-text-coords library using either npm or yarn:

npm install @fnet/ocr-text-coords

Or with yarn:

yarn add @fnet/ocr-text-coords

Usage

The library provides a simple public function that you can use to extract text from images:

Basic Usage

First, import the library into your project:

import extractTextWithCoords from '@fnet/ocr-text-coords';

You can then use the function to process an image:

(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);
  }
})();

Parameters

  • imageInput: A string representing the image input. This can be a file path, a URL, or a Base64-encoded string.
  • language (optional): A string specifying the language(s) for OCR. The default is "eng". You can specify multiple languages by joining their codes with a plus sign (e.g., "eng+tur").

Examples

Here are a few practical examples demonstrating typical use cases:

Extracting Text from a Local File

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);
})();

Extracting Text from a 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);
})();

Extracting Text from a Base64 String

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);
})();

Acknowledgement

This library uses Tesseract.js for OCR processing. Tesseract.js is an open-source OCR engine supported by an active developer community.

Input Schema

$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

版本与发布记录

@fnet/ocr-text-coords 共发布 1 个版本,首次发布于 2024/11/09;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.1.1latest2024/11/092 年前

关于 @fnet/ocr-text-coords 的常见问题

@fnet/ocr-text-coords 是什么?

This project is designed to facilitate the extraction of text and their corresponding bounding box coordinates from images, using the Tesseract.js library. It supports various input formats such as file paths, URLs, or Base64 encoded strings and can handl

如何安装 @fnet/ocr-text-coords?

在项目目录运行 npm install @fnet/ocr-text-coords,或使用 pnpm add / yarn add / bun add。

@fnet/ocr-text-coords 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/fnet__ocr-text-coords 是否存在。

@fnet/ocr-text-coords 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@fnet/ocr-text-coords 可以商用吗?

@fnet/ocr-text-coords 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@fnet/ocr-text-coords 的下载量有多少?

根据 npm 官方下载统计,@fnet/ocr-text-coords 在 2026/10/15 – 2026/11/13 这 30 天内被下载 25,738 次,日均约 858 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@fnet/ocr-text-coords 还在维护吗?

最新版本 0.1.1 发布于 2024/11/09(2 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/11/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。