@the-horizon-dev/fast-face-detection
Version:
Fast face detection package using TensorFlow.js MediaPipe models for browser and Node.js environments
96 lines (95 loc) • 3.46 kB
TypeScript
/**
* @file Main FaceAPI class that orchestrates face detection and landmark detection
*
* This file implements the main API class that coordinates between the face detector
* and landmark detector to provide a complete facial analysis solution.
*/
import { DetectionOptions, MediaElement, PossiblyTrackedFace, PossiblyTrackedFaceDetectionWithLandmarks, DetectionResult } from '../types/types';
/**
* Main API class for face detection functionality.
* This class orchestrates the face detection pipeline, managing the connection
* between face detection and landmark detection.
*
* @example
* // Basic usage
* const api = new FaceAPI();
* const result = await api.detectFaces(imageElement);
* console.log(`Detected ${result.faces.length} faces`);
*/
export declare class FaceAPI {
private faceDetector;
private landmarkDetector;
private options;
private isDisposed;
/**
* Creates a new FaceAPI instance with the specified options
* @param options Detection configuration options
*/
constructor(options?: DetectionOptions);
/**
* Detects faces in an image or video
* @param input Image, video, or canvas element
* @param options Detection options
* @returns Detection result containing faces and timing information
*/
detectFaces(input: MediaElement, options?: DetectionOptions): Promise<DetectionResult<PossiblyTrackedFace>>;
/**
* Detects faces with landmarks in an image or video
* @param input Image, video, or canvas element
* @param options Detection options
* @returns Detection result containing faces with landmarks and timing information
*
* @example
* // Detect faces with landmarks and access points
* const api = new FaceAPI({ maxFaces: 5 });
* const result = await api.detectFacesWithLandmarks(videoElement);
*
* for (const face of result.faces) {
* // Access bounding box
* const { x, y, width, height } = face.detection.box;
*
* // Access landmarks
* const nosePoint = face.landmarks.positions[0];
* console.log(`Nose position: ${nosePoint.x}, ${nosePoint.y}`);
* }
*/
detectFacesWithLandmarks(input: MediaElement, options?: DetectionOptions): Promise<DetectionResult<PossiblyTrackedFaceDetectionWithLandmarks>>;
/**
* Maps face detections to landmarks by combining them
* @param faces Detected face objects
* @param landmarkResultSets Detected landmark sets
* @returns Combined faces with landmarks
* @private
*/
private mapFacesToLandmarks;
/**
* Updates detection options for both face and landmark detectors
* @param options New detection options to apply
*/
updateOptions(options: DetectionOptions): void;
/**
* Preloads and warms up the detection models
* Call this method to improve the performance of the first detection
*/
warmup(): Promise<void>;
/**
* Releases all resources used by the API
* Call this method when face detection is no longer needed
*/
dispose(): void;
/**
* Upscales face bounding boxes by a given factor.
* @private
*/
private upscaleBox;
/**
* Upscales a list of faces (bounding boxes) by a given factor.
* @private
*/
private upscaleFaces;
/**
* Upscales landmark points by a given factor.
* @private
*/
private upscaleLandmarks;
}