UNPKG

ppu-ocv

Version:

A type-safe, modular, chainable image processing library built on top of OpenCV.js with a fluent API leveraging pipeline processing.

68 lines (67 loc) 2.33 kB
import type { CanvasLike } from "./canvas-factory.js"; /** * Options for configuring the deskew service */ export type DeskewOptions = { /** * Enable detailed logging of each processing step. * @default false */ verbose?: boolean; /** * Remove detected boxes with area below this threshold, in pixels. * Used to filter out noise when detecting text regions. * @default 20 */ minimumAreaThreshold?: number; }; /** * Service for calculating the skew angle of an image containing text. * * This service analyzes text regions in an image to determine its skew angle * using multiple methods (minAreaRect, baseline analysis, and Hough transform) * to robustly calculate the average text orientation. * * @example * ```ts * import { DeskewService } from 'ppu-ocv'; * * const service = new DeskewService({ verbose: true }); * const canvas = ...; // your canvas with text * const angle = await service.calculateSkewAngle(canvas); * console.log(`Skew angle: ${angle}°`); * * // Or deskew the image directly * const deskewed = await service.deskewImage(canvas); * ``` */ export declare class DeskewService { private readonly verbose; private readonly minimumAreaThreshold; /** * Create a DeskewService. * @param options - Configuration. See {@link DeskewOptions}. */ constructor(options?: DeskewOptions); private log; /** * Calculate the skew angle of text in a probability map or binary image. * * This method processes the input image to detect text regions and calculates * the average skew angle using multiple robust methods. * * @param canvas - Canvas containing a probability map or binary image of text regions * @returns The calculated skew angle in degrees (positive = clockwise, negative = counter-clockwise) */ calculateSkewAngle(canvas: CanvasLike): Promise<number>; /** * Deskew an image by detecting its skew angle and rotating it. * * This is a convenience method that combines `calculateSkewAngle()` * with rotation to produce a straightened image. * * @param canvas - Canvas containing the image to deskew * @returns A new canvas with the deskewed image */ deskewImage(canvas: CanvasLike): Promise<CanvasLike>; }