Scripts2026年7月17日·1 分钟阅读

Tesseract.js — Pure JavaScript OCR for 100+ Languages

Run optical character recognition entirely in the browser or Node.js with no native dependencies, supporting over 100 languages via a WebAssembly port of the Tesseract engine.

Agent 就绪

这个资产会安全暂存

这个资产会先安全暂存。复制的指令会要求 Agent 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。

Stage only · 17/100策略:需暂存
Agent 入口
任意 MCP/CLI Agent
类型
Script
安装
Stage only
信任
信任等级:Established
入口
Tesseract.js
安全暂存命令
npx -y tokrepo@latest install d5db39a9-8175-11f1-9bc6-00163e2b0d79 --target codex

先暂存文件;激活前需要读取暂存 README 和安装计划。

Introduction

Tesseract.js brings the Tesseract OCR engine to JavaScript through WebAssembly, enabling text extraction from images directly in browsers and Node.js environments. It eliminates the need for server-side OCR services or native binary installations, making document processing accessible to any JavaScript application.

What Tesseract.js Does

  • Extracts printed text from images in over 100 languages including CJK scripts
  • Runs entirely client-side in the browser via WebAssembly with no server round-trips
  • Provides word-level bounding boxes, confidence scores, and paragraph segmentation
  • Supports multiple workers for parallel OCR processing of batch images
  • Detects page orientation and script direction automatically

Architecture Overview

Tesseract.js wraps the C++ Tesseract engine compiled to WebAssembly via Emscripten. A scheduler distributes recognition tasks across web workers (browser) or worker threads (Node.js), each loading trained language data files on demand. The library exposes a Promise-based API that handles worker lifecycle, memory management, and data transfer transparently.

Self-Hosting & Configuration

  • Install via npm or load from a CDN script tag for browser use
  • Language data files are fetched from a CDN by default; set workerPath and langPath to serve them from your own origin
  • Configure tessedit_pageseg_mode to optimize for single lines, blocks, or full pages
  • Use worker.setParameters to whitelist character sets or switch OCR engine modes (legacy vs LSTM)
  • Pre-load language data with worker.loadLanguage to avoid latency at recognition time

Key Features

  • Zero native dependencies: pure JS and WASM, works in any modern browser or Node.js
  • Scheduler API for parallel processing across multiple workers
  • Incremental progress callbacks for real-time UI feedback during recognition
  • Supports combined language models (e.g., eng+fra) for multilingual documents
  • Compatible with image inputs from Canvas, File, Buffer, URL, or base64

Comparison with Similar Tools

  • Google Cloud Vision — cloud-hosted with higher accuracy on complex layouts, but requires API keys and per-request billing
  • Paddle OCR — Python-based with strong CJK accuracy; heavier runtime, not browser-native
  • EasyOCR — Python library with GPU support; better for server pipelines, not for client-side use
  • Amazon Textract — managed service with table and form extraction; vendor lock-in and cost at scale

FAQ

Q: How accurate is Tesseract.js compared to cloud OCR services? A: For clean printed text, accuracy is comparable. For complex layouts, handwriting, or low-quality scans, cloud services with custom models tend to perform better.

Q: Can it run in a web browser without a server? A: Yes. The entire engine runs client-side via WebAssembly. Language data is fetched once and can be cached.

Q: Does it support PDF input? A: Not directly. Convert PDF pages to images first using a library like pdf.js, then pass the images to Tesseract.js.

Q: How large are the language data files? A: The English trained data file is roughly 4 MB (gzipped). CJK languages are larger, around 10-20 MB each.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产