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
52 lines (51 loc) • 1.8 kB
TypeScript
import type { Contours } from "ppu-ocv";
import type { Box } from "../../interface.js";
/**
* Calculates resize dimensions keeping the longest side at or below `maxSideLength`.
*
* Returns the new dimensions and the scale ratio applied.
*/
export declare function calculateResizeDimensions(originalWidth: number, originalHeight: number, maxSideLength: number): {
width: number;
height: number;
ratio: number;
};
/**
* Expands a bounding rect by padding derived from its height, clamped to canvas bounds.
*/
export declare function applyPaddingToRect(rect: {
x: number;
y: number;
width: number;
height: number;
}, maxWidth: number, maxHeight: number, paddingVertical: number, paddingHorizontal: number): {
x: number;
y: number;
width: number;
height: number;
};
/**
* Maps a rect from the resized/padded tensor space back to original image coordinates.
*/
export declare function convertToOriginalCoordinates(rect: {
x: number;
y: number;
width: number;
height: number;
}, resizeRatio: number, originalWidth: number, originalHeight: number): Box;
/**
* Iterates OpenCV contours and converts each to a padded, coordinate-mapped `Box`.
*/
export declare function extractBoxesFromContours(contours: Contours, width: number, height: number, resizeRatio: number, originalWidth: number, originalHeight: number, minBoxArea: number, paddingVertical: number, paddingHorizontal: number): Box[];
/**
* Converts raw region bboxes from `findRegions` into `Box` objects clamped to the original image.
*/
export declare function extractBoxesFromRegions(regions: Array<{
bbox: {
x0: number;
y0: number;
x1: number;
y1: number;
};
area: number;
}>, originalWidth: number, originalHeight: number): Box[];