UNPKG

id-scanner-lib

Version:

Browser-based ID card, QR code, and face recognition scanner with liveness detection

175 lines (174 loc) 5.34 kB
/** * @file 外部库类型声明 * @description 为外部依赖库声明类型定义 */ /** * TensorFlow.js 相关类型 */ declare module '@tensorflow/tfjs' { interface Tensor<R extends Rank = Rank> { dataId: object; id: number; shape: number[]; dtype: string; size: number; rank: number; dispose(): void; } type Rank = 'R0' | 'R1' | 'R2' | 'R3' | 'R4' | 'R5' | 'R6'; function ready(): Promise<void>; function dispose(): void; } /** * face-api.js 相关类型 */ declare module '@vladmandic/face-api' { namespace tf { function dispose(): Promise<void>; } namespace env { function monkeyPatch(env: any): void; } type TNetInput = HTMLImageElement | HTMLVideoElement | HTMLCanvasElement | ImageData | { toString(): string; } | string; interface FaceDetectionWithLandmarks { detection: FaceDetection; landmarks: FaceLandmarks68 | FaceLandmarks68TinyNet; getRefRect(): any; forwardFaceDetection(): FaceDetection; } interface WithFaceDescriptor<T> { descriptor: Float32Array; } interface WithAge { age: number; } interface WithGender { gender: string; genderProbability: number; } interface FaceMatch { label: string; distance: number; } interface WithFaceExpressions { expressions: { neutral: number; happy: number; sad: number; angry: number; fearful: number; disgusted: number; surprised: number; }; } interface IFaceLandmarks { positions: Point[]; shift(point: Point): IFaceLandmarks; forSize<T extends IFaceLandmarks>(width: number, height: number): T; } interface IRect { x: number; y: number; width: number; height: number; } interface IBoundingBox extends IRect { left: number; top: number; right: number; bottom: number; } interface IFaceDetection { score: number; box: IBoundingBox; } class Point { x: number; y: number; constructor(x: number, y: number); } class FaceDetection implements IFaceDetection { score: number; box: IBoundingBox; constructor(score: number, box: IBoundingBox); } class FaceLandmarks68 implements IFaceLandmarks { positions: Point[]; constructor(points: Point[]); shift(point: Point): FaceLandmarks68; forSize<T extends IFaceLandmarks>(width: number, height: number): T; } class FaceLandmarks68TinyNet extends FaceLandmarks68 { constructor(points: Point[]); } class SsdMobilenetv1Options { constructor(options?: { minConfidence?: number; maxResults?: number; }); } class TinyFaceDetectorOptions { constructor(options?: { inputSize?: number; scoreThreshold?: number; }); } class MtcnnOptions { constructor(options?: { minFaceSize?: number; scaleFactor?: number; minConfidence?: number; }); } class FaceRecognitionNet { constructor(); loadFromUri(uri: string): Promise<void>; } class FaceExpressionNet { constructor(); loadFromUri(uri: string): Promise<void>; } class AgeGenderNet { constructor(); loadFromUri(uri: string): Promise<void>; } interface NeuralNetwork { loadFromUri(uri: string): Promise<void>; isLoaded: boolean; dispose(): void; } const nets: { ssdMobilenetv1: NeuralNetwork; tinyFaceDetector: NeuralNetwork; faceLandmark68Net: NeuralNetwork; faceLandmark68TinyNet: NeuralNetwork; faceRecognitionNet: NeuralNetwork; faceExpressionNet: NeuralNetwork; ageGenderNet: NeuralNetwork; mtcnn: NeuralNetwork; }; function createCanvasFromMedia(media: TNetInput): HTMLCanvasElement; function detectAllFaces(input: TNetInput, options?: SsdMobilenetv1Options | TinyFaceDetectorOptions | MtcnnOptions): DetectAllFacesTask; interface DetectAllFacesTask { withFaceLandmarks(useTinyModel?: boolean): DetectAllFacesWithLandmarksTask; run(): Promise<FaceDetection[]>; } interface DetectAllFacesWithLandmarksTask { withFaceExpressions(): DetectAllFacesWithFaceExpressionsTask; withAgeAndGender(): DetectAllFacesWithAgeAndGenderTask; run(): Promise<FaceDetectionWithLandmarks[]>; } interface DetectAllFacesWithFaceExpressionsTask { withAgeAndGender(): DetectAllFacesWithAgeAndGenderTask; run(): Promise<Array<FaceDetectionWithLandmarks & WithFaceExpressions>>; } interface DetectAllFacesWithAgeAndGenderTask { withFaceDescriptors(): DetectAllFacesWithFaceDescriptorsTask; run(): Promise<Array<FaceDetectionWithLandmarks & WithFaceExpressions & WithAge & WithGender>>; } interface DetectAllFacesWithFaceDescriptorsTask { run(): Promise<Array<FaceDetectionWithLandmarks & WithFaceExpressions & WithAge & WithGender & WithFaceDescriptor<any>>>; } }