ppu-paddle-ocr
Version:
Lightweight, probably the fastest PaddleOCR SDK in TypeScript. Runs anywhere JavaScript runs: Node.js, Bun, Deno, mobile react-native, web browsers, and browser extensions. Docker & CLI supported. The official SDK is browser-only. Accurate text detection
31 lines (30 loc) • 1.28 kB
TypeScript
import type { Tensor } from "onnxruntime-common";
/** CTC blank token index. */
export declare const BLANK_INDEX = 0;
/** Unknown token marker used in PaddleOCR dictionaries. */
export declare const UNK_TOKEN = "<unk>";
/** Minimum crop width (pixels) fed to the recognition model. */
export declare const MIN_CROP_WIDTH = 8;
/**
* Performs greedy CTC decoding over raw model logits.
*
* Hot loop: argmax and character handling are inlined, and per-character
* confidence is accumulated as a running sum instead of a backing array.
*/
export declare function ctcGreedyDecode(logits: Float32Array, sequenceLength: number, numClasses: number, charDict: string[]): {
text: string;
confidence: number;
};
/**
* Decodes an ONNX output tensor into text using the supplied character dictionary.
*
* Prepends a blank slot when the dict is one entry shorter than the model's class count
* (issue #15 compatibility).
*
* When `verbose` is set, a dictionary/model size mismatch is reported once (such a
* mismatch produces garbage output, so it usually signals the wrong dictionary).
*/
export declare function decodeResults(outputTensor: Tensor, charactersDictionary: string[], numClassesFromShape: number, verbose?: boolean): {
text: string;
confidence: number;
};