import type { InferenceSession } from "onnxruntime-common"; import type { CoreCanvas, PlatformProvider } from "../core/platform.js"; import { BaseAnalysis } from "./base.interface.js"; /** * Configuration options for face spoofing detection models */ export interface SpoofingOptions { /** Threshold score values for spoofing detection */ threshold: number; /** Wether to activate the anti-spoofing analysis */ enable: boolean; } /** * Spoofing detection result */ export interface SpoofingResult { /** Whether the image is real or fake */ real: boolean; /** The given score from analysis (confidence of the predicted label) */ score: number; /** Probability of the image being real (0-1) */ realness: number; /** Probability of the image being fake (0-1) */ fakeness: number; } export declare class SpoofingDetection extends BaseAnalysis { protected className: string; protected firstModelPath: string; protected secondModelPath: string; protected firstSession: InferenceSession | null; protected secondSession: InferenceSession | null; protected options: SpoofingOptions; constructor(options?: Partial, platform?: PlatformProvider); initialize(): Promise; /** * Checks if the model has been initialized * @returns True if initialized */ protected isInitialized(): boolean; /** * Analyze whether a face is spoofed * @param image The image (full image recommended) * @param facialArea Optional facial bounding box {x, y, width, height}. * If not provided, uses the entire image as the facial area. */ analyze(image: ArrayBuffer | CoreCanvas, facialArea?: { x: number; y: number; width: number; height: number; }): Promise; /** * Preprocess image by cropping from original image with scale and resizing */ protected preprocessPromise(canvas: CoreCanvas, bbox: { x: number; y: number; width: number; height: number; }, scale: number, outW: number, outH: number, session: InferenceSession): Promise; /** * Preprocess image by cropping from original image with scale and resizing */ protected preprocessWithCrop(canvas: CoreCanvas, bbox: { x: number; y: number; width: number; height: number; }, scale: number, outW: number, outH: number): Float32Array; /** * Simple preprocess by resizing only (for pre-cropped faces) */ protected preprocess(canvas: CoreCanvas, outW: number, outH: number): Float32Array; /** * Convert canvas to tensor in CHW format */ protected canvasToTensor(canvas: CoreCanvas, width: number, height: number): Float32Array; /** * Calculate new bounding box with scale */ protected getNewBox(srcW: number, srcH: number, bbox: { x: number; y: number; width: number; height: number; }, scale: number): { x: number; y: number; width: number; height: number; }; /** * Run inference on a model */ protected inference(session: InferenceSession, tensor: Float32Array, shape: number[]): Promise; /** * Apply softmax to logits */ protected softmax(logits: Float32Array): Float32Array; /** * Postprocess model outputs */ protected postprocess(firstOutput: InferenceSession.OnnxValueMapType, secondOutput: InferenceSession.OnnxValueMapType): SpoofingResult; destroy(): Promise; }