UNPKG

@the-horizon-dev/fast-face-detection

Version:

Fast face detection package using TensorFlow.js MediaPipe models for browser and Node.js environments

41 lines (40 loc) 1.56 kB
/** * Utility functions for image processing */ import { Box, Point } from '../types/types'; type DownscaleInput = HTMLImageElement | HTMLVideoElement | HTMLCanvasElement; export declare class ImageUtils { /** * Crops a face from an image based on the bounding box * @returns An object containing the cropped canvas and the top-left offset used */ static cropFace(canvas: HTMLCanvasElement, box: Box, margin?: number): { croppedCanvas: HTMLCanvasElement; offsetX: number; offsetY: number; }; /** * Draws facial landmarks on a canvas */ static drawLandmarks(canvas: HTMLCanvasElement, points: Point[], color?: string, size?: number): void; /** * Draws a bounding box on a canvas */ static drawBox(canvas: HTMLCanvasElement, box: Box, color?: string, lineWidth?: number): void; /** * Converts an image or video to canvas */ static elementToCanvas(element: HTMLImageElement | HTMLVideoElement | HTMLCanvasElement): HTMLCanvasElement; /** * Downscales an image element to a target width, maintaining aspect ratio. * Only works in browser environments. * @param element The input image, video, or canvas. * @param targetWidth The desired width for the downscaled image. * @returns Object containing the downscaled canvas and the scaling factor used. */ static downscaleImage(element: DownscaleInput, targetWidth: number): { downscaledCanvas: HTMLCanvasElement; scaleFactor: number; }; } export {};