@sssxyd/face-liveness-detector 0.4.0-alpha.9 → 0.4.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +115 -146
- package/README.md +21 -52
- package/dist/index.esm.js +2218 -3077
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2218 -3077
- package/dist/index.js.map +1 -1
- package/dist/types/browser_utils.d.ts +3 -3
- package/dist/types/browser_utils.d.ts.map +1 -1
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/dlp-color-wheel-detector.d.ts +76 -0
- package/dist/types/dlp-color-wheel-detector.d.ts.map +1 -0
- package/dist/types/face-detection-engine.d.ts +59 -20
- package/dist/types/face-detection-engine.d.ts.map +1 -1
- package/dist/types/face-detection-state.d.ts +1 -5
- package/dist/types/face-detection-state.d.ts.map +1 -1
- package/dist/types/face-frontal-calculator.d.ts +3 -3
- package/dist/types/face-frontal-calculator.d.ts.map +1 -1
- package/dist/types/image-quality-calculator.d.ts +10 -23
- package/dist/types/image-quality-calculator.d.ts.map +1 -1
- package/dist/types/motion-liveness-detector.d.ts +258 -124
- package/dist/types/motion-liveness-detector.d.ts.map +1 -1
- package/dist/types/optical-distortion-detector.d.ts +116 -0
- package/dist/types/optical-distortion-detector.d.ts.map +1 -0
- package/dist/types/screen-capture-detector.d.ts +74 -115
- package/dist/types/screen-capture-detector.d.ts.map +1 -1
- package/dist/types/screen-corners-contour-detector.d.ts +78 -0
- package/dist/types/screen-corners-contour-detector.d.ts.map +1 -0
- package/dist/types/screen-flicker-detector.d.ts +103 -0
- package/dist/types/screen-flicker-detector.d.ts.map +1 -0
- package/dist/types/screen-moire-pattern-detect.d.ts.map +1 -1
- package/dist/types/screen-response-time-detector.d.ts +70 -0
- package/dist/types/screen-response-time-detector.d.ts.map +1 -0
- package/dist/types/screen-rgb-emission-detect.d.ts.map +1 -1
- package/dist/types/types.d.ts +8 -54
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/video-frame-collector.d.ts +111 -0
- package/dist/types/video-frame-collector.d.ts.map +1 -0
- package/package.json +2 -1
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* 将绘制图片的canvas转换为mat
|
|
3
3
|
* @param {any} cv OpenCV实例
|
|
4
4
|
* @param {HTMLCanvasElement} canvas canvas元素
|
|
5
|
-
* @param {
|
|
6
|
-
* @returns {any | null} -
|
|
5
|
+
* @param {any} dstMat 目标Mat对象,将canvas数据写入此Mat
|
|
6
|
+
* @returns {any | null} - 返回传入的Mat对象,如果转换失败则返回null
|
|
7
7
|
*/
|
|
8
|
-
export declare function drawCanvasToMat(cv: any, canvas: HTMLCanvasElement,
|
|
8
|
+
export declare function drawCanvasToMat(cv: any, canvas: HTMLCanvasElement, dstMat: any): any | null;
|
|
9
9
|
export declare function matToGray(cv: any, mat: any): any | null;
|
|
10
10
|
/**
|
|
11
11
|
* Convert OpenCV Mat to Base64 JPEG image
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser_utils.d.ts","sourceRoot":"","sources":["../../src/browser_utils.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"browser_utils.d.ts","sourceRoot":"","sources":["../../src/browser_utils.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI,CAsB3F;AAED,wBAAgB,SAAS,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI,CAWvD;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,MAAY,GAAG,MAAM,GAAG,IAAI,CA6BvF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAiDhF;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,UAAU,CAAC,EAAE,OAAO,CAAC,0BAA0B,CAAC,GAC/C,qBAAqB,CAwBvB"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DLP色轮检测器 - 检测DLP投影仪的特有伪影
|
|
3
|
+
*
|
|
4
|
+
* 核心原理:
|
|
5
|
+
* - DLP投影仪使用单色DMD芯片 + RGB色轮
|
|
6
|
+
* - 色轮以高频率(120-144Hz)轮换RGB颜色
|
|
7
|
+
* - 摄像头如果不同步捕捉,会看到RGB分离现象
|
|
8
|
+
*
|
|
9
|
+
* 特征:
|
|
10
|
+
* 1. 高对比度边界处出现"彩虹纹"(R左/B右分离)
|
|
11
|
+
* 2. 快速移动物体边缘有明显的RGB分离
|
|
12
|
+
* 3. 静止物体通常正常(因为色轮平均后是白色)
|
|
13
|
+
*
|
|
14
|
+
* 检测方法:
|
|
15
|
+
* 1. 找高对比度边界区域
|
|
16
|
+
* 2. 分析边界处R、G、B通道的位置差异
|
|
17
|
+
* 3. 如果R领先,B延后 → DLP特征
|
|
18
|
+
*/
|
|
19
|
+
import { VideoFrameCollector } from "./video-frame-collector";
|
|
20
|
+
export interface DLPColorWheelDetectorConfig {
|
|
21
|
+
bufferSize: number;
|
|
22
|
+
edgeThreshold: number;
|
|
23
|
+
minChannelSeparationPixels: number;
|
|
24
|
+
separationConfidenceThreshold: number;
|
|
25
|
+
samplingStride: number;
|
|
26
|
+
}
|
|
27
|
+
export interface DLPColorWheelDetectionResult {
|
|
28
|
+
isScreenCapture: boolean;
|
|
29
|
+
confidence: number;
|
|
30
|
+
hasColorSeparation: boolean;
|
|
31
|
+
colorSeparationPixels: number;
|
|
32
|
+
redLeadPixels?: number;
|
|
33
|
+
blueDelayPixels?: number;
|
|
34
|
+
sampledEdgePixelCount: number;
|
|
35
|
+
estimatedColorWheelFrequency?: number;
|
|
36
|
+
details?: {
|
|
37
|
+
edgeLocations: number[];
|
|
38
|
+
separationDistances: number[];
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export declare class DLPColorWheelDetector {
|
|
42
|
+
private config;
|
|
43
|
+
private frameCollector;
|
|
44
|
+
constructor(frameCollector: VideoFrameCollector, config: DLPColorWheelDetectorConfig);
|
|
45
|
+
/**
|
|
46
|
+
* 获取当前缓冲区中的帧数
|
|
47
|
+
*/
|
|
48
|
+
getBufferedFrameCount(): number;
|
|
49
|
+
/**
|
|
50
|
+
* 执行DLP色轮检测分析
|
|
51
|
+
*/
|
|
52
|
+
analyze(): DLPColorWheelDetectionResult;
|
|
53
|
+
/**
|
|
54
|
+
* 重置检测器
|
|
55
|
+
* 注意:帧缓冲由 FrameCollector 管理
|
|
56
|
+
*/
|
|
57
|
+
reset(): void;
|
|
58
|
+
/**
|
|
59
|
+
* 检测高对比度边界
|
|
60
|
+
* 返回边界的x坐标位置
|
|
61
|
+
*/
|
|
62
|
+
private detectHighContrastEdges;
|
|
63
|
+
/**
|
|
64
|
+
* 分析单条边界的RGB分离
|
|
65
|
+
*
|
|
66
|
+
* DLP特征:
|
|
67
|
+
* - R通道的边界比G靠前(向左)
|
|
68
|
+
* - B通道的边界比G靠后(向右)
|
|
69
|
+
*/
|
|
70
|
+
private analyzeRGBSeparation;
|
|
71
|
+
/**
|
|
72
|
+
* 找导数数组中的峰值位置
|
|
73
|
+
*/
|
|
74
|
+
private findPeakPosition;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=dlp-color-wheel-detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dlp-color-wheel-detector.d.ts","sourceRoot":"","sources":["../../src/dlp-color-wheel-detector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAA;AAE7D,MAAM,WAAW,2BAA2B;IAE1C,UAAU,EAAE,MAAM,CAAA;IAGlB,aAAa,EAAE,MAAM,CAAA;IAGrB,0BAA0B,EAAE,MAAM,CAAA;IAGlC,6BAA6B,EAAE,MAAM,CAAA;IAGrC,cAAc,EAAE,MAAM,CAAA;CACvB;AAED,MAAM,WAAW,4BAA4B;IAC3C,eAAe,EAAE,OAAO,CAAA;IACxB,UAAU,EAAE,MAAM,CAAA;IAGlB,kBAAkB,EAAE,OAAO,CAAA;IAC3B,qBAAqB,EAAE,MAAM,CAAA;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,eAAe,CAAC,EAAE,MAAM,CAAA;IAGxB,qBAAqB,EAAE,MAAM,CAAA;IAG7B,4BAA4B,CAAC,EAAE,MAAM,CAAA;IAErC,OAAO,CAAC,EAAE;QACR,aAAa,EAAE,MAAM,EAAE,CAAA;QACvB,mBAAmB,EAAE,MAAM,EAAE,CAAA;KAC9B,CAAA;CACF;AAED,qBAAa,qBAAqB;IAChC,OAAO,CAAC,MAAM,CAA6B;IAC3C,OAAO,CAAC,cAAc,CAAqB;gBAE/B,cAAc,EAAE,mBAAmB,EAAE,MAAM,EAAE,2BAA2B;IAKpF;;OAEG;IACH,qBAAqB,IAAI,MAAM;IAI/B;;OAEG;IACH,OAAO,IAAI,4BAA4B;IA8HvC;;;OAGG;IACH,KAAK,IAAI,IAAI;IAKb;;;OAGG;IACH,OAAO,CAAC,uBAAuB;IAyC/B;;;;;;OAMG;IACH,OAAO,CAAC,oBAAoB;IAgE5B;;OAEG;IACH,OAAO,CAAC,gBAAgB;CAgBzB"}
|
|
@@ -14,15 +14,20 @@ export declare class FaceDetectionEngine extends SimpleEventEmitter {
|
|
|
14
14
|
private cv;
|
|
15
15
|
private human;
|
|
16
16
|
private engineState;
|
|
17
|
+
private videoFPS;
|
|
18
|
+
private lastDebugLogTime;
|
|
19
|
+
private debugLogLevelPriority;
|
|
17
20
|
private videoElement;
|
|
18
21
|
private stream;
|
|
19
22
|
private frameCanvasElement;
|
|
20
23
|
private frameCanvasContext;
|
|
21
|
-
private
|
|
22
|
-
private faceCanvasContext;
|
|
23
|
-
private detectionFrameId;
|
|
24
|
+
private animationFrameId;
|
|
24
25
|
private actualVideoWidth;
|
|
25
26
|
private actualVideoHeight;
|
|
27
|
+
private preallocatedBgrFrame;
|
|
28
|
+
private preallocatedGrayFrame;
|
|
29
|
+
private isDetectingFrameActive;
|
|
30
|
+
private frameIndex;
|
|
26
31
|
private detectionState;
|
|
27
32
|
/**
|
|
28
33
|
* Constructor
|
|
@@ -41,6 +46,37 @@ export declare class FaceDetectionEngine extends SimpleEventEmitter {
|
|
|
41
46
|
private getStackTrace;
|
|
42
47
|
updateOptions(options?: Partial<FaceDetectionEngineOptions>): void;
|
|
43
48
|
getEngineState(): EngineState;
|
|
49
|
+
/**
|
|
50
|
+
* Atomically transition engine state with validation
|
|
51
|
+
* Ensures state transitions follow the valid state machine
|
|
52
|
+
* @param newState - Target engine state
|
|
53
|
+
* @param context - Debug context for logging
|
|
54
|
+
* @returns true if transition succeeded, false otherwise
|
|
55
|
+
*/
|
|
56
|
+
private transitionEngineState;
|
|
57
|
+
/**
|
|
58
|
+
* Check if state transition is valid according to state machine rules
|
|
59
|
+
* Valid transitions:
|
|
60
|
+
* - IDLE -> INITIALIZING, INITIALIZING -> READY, READY -> DETECTING, DETECTING -> READY
|
|
61
|
+
* - Any -> IDLE (error recovery)
|
|
62
|
+
*/
|
|
63
|
+
private isValidStateTransition;
|
|
64
|
+
/**
|
|
65
|
+
* Transition detection period state
|
|
66
|
+
* @param newPeriod - Target detection period
|
|
67
|
+
* @returns true if transition succeeded
|
|
68
|
+
*/
|
|
69
|
+
private transitionDetectionPeriod;
|
|
70
|
+
/**
|
|
71
|
+
* Partially reset detection state (keeps engine initialized)
|
|
72
|
+
* Used when detection fails but engine should remain ready
|
|
73
|
+
*/
|
|
74
|
+
private partialResetDetectionState;
|
|
75
|
+
/**
|
|
76
|
+
* Fully reset detection state and resources
|
|
77
|
+
* Used when stopping detection or reinitializing
|
|
78
|
+
*/
|
|
79
|
+
private fullResetDetectionState;
|
|
44
80
|
/**
|
|
45
81
|
* Initialize the detection engine
|
|
46
82
|
* Loads Human.js and OpenCV.js libraries
|
|
@@ -60,6 +96,7 @@ export declare class FaceDetectionEngine extends SimpleEventEmitter {
|
|
|
60
96
|
startDetection(videoElement: HTMLVideoElement): Promise<void>;
|
|
61
97
|
/**
|
|
62
98
|
* Stop face detection
|
|
99
|
+
* Performs comprehensive cleanup to prevent memory leaks and UI freezing
|
|
63
100
|
* @param success - Whether to display the best collected image
|
|
64
101
|
*/
|
|
65
102
|
stopDetection(success: boolean): void;
|
|
@@ -68,22 +105,26 @@ export declare class FaceDetectionEngine extends SimpleEventEmitter {
|
|
|
68
105
|
* @returns Current configuration
|
|
69
106
|
*/
|
|
70
107
|
getOptions(): FaceDetectionEngineOptions;
|
|
71
|
-
|
|
72
|
-
* Reset detection state
|
|
73
|
-
*/
|
|
74
|
-
private resetDetectionState;
|
|
75
|
-
/**
|
|
76
|
-
* Schedule next detection frame
|
|
77
|
-
*/
|
|
78
|
-
private scheduleNextDetection;
|
|
108
|
+
private updateVideoFPS;
|
|
79
109
|
/**
|
|
80
110
|
* Cancel pending detection frame
|
|
81
111
|
*/
|
|
82
112
|
private cancelPendingDetection;
|
|
83
113
|
/**
|
|
84
114
|
* Main detection loop
|
|
115
|
+
* Called every frame via requestAnimationFrame
|
|
116
|
+
* Orchestrates the detection pipeline with clear separation of concerns
|
|
85
117
|
*/
|
|
86
118
|
private detect;
|
|
119
|
+
/**
|
|
120
|
+
* Capture video frame and convert to BGR and Grayscale Mat objects
|
|
121
|
+
* @returns {Object | null} Object with bgrFrame and grayFrame, or null if failed
|
|
122
|
+
*/
|
|
123
|
+
private captureAndPrepareFrames;
|
|
124
|
+
/**
|
|
125
|
+
* Perform main face detection and handle results
|
|
126
|
+
*/
|
|
127
|
+
private performFaceDetection;
|
|
87
128
|
private getPerformActionCount;
|
|
88
129
|
/**
|
|
89
130
|
* Handle single face detection
|
|
@@ -121,22 +162,20 @@ export declare class FaceDetectionEngine extends SimpleEventEmitter {
|
|
|
121
162
|
private emitDebug;
|
|
122
163
|
/**
|
|
123
164
|
* Draw video frame to canvas (internal use, not converted to Base64)
|
|
165
|
+
* Handles potential runtime resolution changes from camera stream
|
|
124
166
|
* @returns {HTMLCanvasElement | null} Canvas after drawing, returns null if failed
|
|
125
167
|
*/
|
|
126
168
|
private drawVideoToCanvas;
|
|
127
169
|
private clearFrameCanvas;
|
|
128
|
-
private clearFaceCanvas;
|
|
129
170
|
/**
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* @returns {string | null} Base64 格式的 JPEG 图片数据
|
|
171
|
+
* Ensure preallocated Mat objects exist with correct dimensions
|
|
172
|
+
* Creates both BGR and Gray Mat for reuse
|
|
133
173
|
*/
|
|
134
|
-
private
|
|
174
|
+
private ensurePreallocatedMats;
|
|
135
175
|
/**
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
* @returns {string | null} Base64 encoded JPEG image data
|
|
176
|
+
* Clear preallocated Mat objects
|
|
177
|
+
* Called when resolution changes or detection stops
|
|
139
178
|
*/
|
|
140
|
-
private
|
|
179
|
+
private clearPreallocatedMats;
|
|
141
180
|
}
|
|
142
181
|
//# sourceMappingURL=face-detection-engine.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"face-detection-engine.d.ts","sourceRoot":"","sources":["../../src/face-detection-engine.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AC,gBAAgB;IAgBxB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAuCxB;;OAEG;IACH,OAAO,CAAC,YAAY;IAuCpB;;OAEG;IACH,OAAO,CAAC,SAAS;IA4CjB;;;;OAIG;IACH,OAAO,CAAC,iBAAiB;IAsEzB,OAAO,CAAC,gBAAgB;IAqBxB;;;OAGG;IACH,OAAO,CAAC,sBAAsB;IAuC9B;;;OAGG;IACH,OAAO,CAAC,qBAAqB;CA2B9B"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { DetectionPeriod, LivenessAction } from "./enums";
|
|
2
2
|
import { MotionLivenessDetector } from "./motion-liveness-detector";
|
|
3
|
-
import { ScreenCaptureDetector } from './screen-capture-detector';
|
|
4
|
-
import { ResolvedEngineOptions } from "./types";
|
|
5
3
|
/**
|
|
6
4
|
* Internal detection state interface
|
|
7
5
|
*/
|
|
@@ -19,18 +17,16 @@ export declare class DetectionState {
|
|
|
19
17
|
lastFrontalScore: number;
|
|
20
18
|
motionDetector: MotionLivenessDetector | null;
|
|
21
19
|
liveness: boolean;
|
|
22
|
-
screenDetector: ScreenCaptureDetector | null;
|
|
23
20
|
constructor(options: Partial<DetectionState>);
|
|
24
21
|
reset(): void;
|
|
25
22
|
needFrontalFace(): boolean;
|
|
26
23
|
isReadyToVerify(minCollectCount: number): boolean;
|
|
27
24
|
onActionStarted(nextAction: LivenessAction, timeoutMills: number, timeoutCallback: () => void): void;
|
|
28
25
|
onActionCompleted(): void;
|
|
29
|
-
setCVInstance(cvInstance: any): void;
|
|
30
26
|
/**
|
|
31
27
|
* Clear action verify timeout
|
|
32
28
|
*/
|
|
33
29
|
private clearActionVerifyTimeout;
|
|
34
30
|
}
|
|
35
|
-
export declare function createDetectionState(
|
|
31
|
+
export declare function createDetectionState(): DetectionState;
|
|
36
32
|
//# sourceMappingURL=face-detection-state.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"face-detection-state.d.ts","sourceRoot":"","sources":["../../src/face-detection-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,
|
|
1
|
+
{"version":3,"file":"face-detection-state.d.ts","sourceRoot":"","sources":["../../src/face-detection-state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,SAAS,CAAA;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAEnE;;GAEG;AACH,qBAAa,cAAc;IACvB,MAAM,EAAE,eAAe,CAAyB;IAChD,SAAS,EAAE,MAAM,CAAoB;IACrC,YAAY,EAAE,MAAM,CAAI;IACxB,oBAAoB,EAAE,MAAM,CAAI;IAChC,gBAAgB,EAAE,MAAM,CAAI;IAC5B,cAAc,EAAE,MAAM,GAAG,IAAI,CAAO;IACpC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAO;IACnC,gBAAgB,EAAE,GAAG,CAAC,cAAc,CAAC,CAAY;IACjD,aAAa,EAAE,cAAc,GAAG,IAAI,CAAO;IAC3C,mBAAmB,EAAE,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,IAAI,CAAO;IAChE,gBAAgB,EAAE,MAAM,CAAI;IAC5B,cAAc,EAAE,sBAAsB,GAAG,IAAI,CAAO;IACpD,QAAQ,EAAE,OAAO,CAAQ;gBAEb,OAAO,EAAE,OAAO,CAAC,cAAc,CAAC;IAI5C,KAAK,IAAI,IAAI;IAab,eAAe,IAAI,OAAO;IAK1B,eAAe,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO;IAUjD,eAAe,CAAC,UAAU,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,IAAI,GAAG,IAAI;IASpG,iBAAiB,IAAI,IAAI;IASzB;;OAEG;IACH,OAAO,CAAC,wBAAwB;CAMnC;AAID,wBAAgB,oBAAoB,IAAI,cAAc,CAIrD"}
|
|
@@ -32,7 +32,7 @@ export interface AngleAnalysisResult {
|
|
|
32
32
|
* @param {any} cv - OpenCV 实例(用于轮廓对称性检测)
|
|
33
33
|
* @param {FaceResult} face - 人脸检测结果(包含 rotation 和 annotations 信息)
|
|
34
34
|
* @param {Array<GestureResult>} gestures - 检测到的手势/表情数组(可选)
|
|
35
|
-
* @param {any}
|
|
35
|
+
* @param {any} grayFrame - OpenCV Mat 对象(图像数据,用于轮廓检测)
|
|
36
36
|
* @param {FaceFrontalFeatures} config - 正对度配置参数(包含角度阈值)
|
|
37
37
|
* @returns {number} 正对度评分 (0-1),1 表示完全正对
|
|
38
38
|
*
|
|
@@ -42,9 +42,9 @@ export interface AngleAnalysisResult {
|
|
|
42
42
|
* if (score > 0.9) {
|
|
43
43
|
* console.log('人脸足够正对')
|
|
44
44
|
* }
|
|
45
|
-
*
|
|
45
|
+
* grayFrame.delete()
|
|
46
46
|
*/
|
|
47
|
-
export declare function calcFaceFrontal(cv: any, face: FaceResult, gestures: Array<GestureResult>,
|
|
47
|
+
export declare function calcFaceFrontal(cv: any, face: FaceResult, gestures: Array<GestureResult>, grayFrame: any, config: FaceFrontalFeatures): number;
|
|
48
48
|
/**
|
|
49
49
|
* 使用手势识别方法检查人脸正对度
|
|
50
50
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"face-frontal-calculator.d.ts","sourceRoot":"","sources":["../../src/face-frontal-calculator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAA;AAC7D,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAG7C;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,MAAM,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,eAAe,CAC7B,EAAE,EAAE,GAAG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D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,mBAAmB,GAAG,MAAM,EAAE,CAwChG"}
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* 图像质量检测模块
|
|
3
3
|
*
|
|
4
|
-
* 综合检测人脸图像的:
|
|
5
|
-
* 1. 完整度检测 - 人脸是否完整在框内
|
|
6
|
-
* 2. 模糊度检测 - 图像是否清晰
|
|
7
|
-
* 3. 轮廓清晰度 - 轮廓的连通性和完整度
|
|
8
|
-
*
|
|
9
|
-
* 使用混合检测策略,结合 Human.js 和 OpenCV.js 优势
|
|
10
4
|
*/
|
|
11
|
-
import { FaceResult } from '@vladmandic/human';
|
|
12
5
|
import { ImageQualityFeatures } from './types';
|
|
13
6
|
/**
|
|
14
7
|
* 单个检测指标的结果
|
|
@@ -37,30 +30,24 @@ export interface ImageQualityResult {
|
|
|
37
30
|
suggestions?: string[];
|
|
38
31
|
}
|
|
39
32
|
/**
|
|
40
|
-
*
|
|
33
|
+
* 计算图像清晰度评分
|
|
41
34
|
*
|
|
42
|
-
*
|
|
43
|
-
* -
|
|
44
|
-
* -
|
|
35
|
+
* 综合检测图像的清晰度,使用两个指标:
|
|
36
|
+
* - 拉普拉斯方差 (60%):检测边缘清晰程度
|
|
37
|
+
* - Sobel 梯度清晰度 (40%):检测纹理梯度强度
|
|
45
38
|
*
|
|
46
39
|
* @param cv - OpenCV.js 对象,用于执行图像处理操作
|
|
47
|
-
* @param
|
|
48
|
-
* @param face - 人脸检测结果,包含人脸框位置和其他检测信息
|
|
49
|
-
* @param imageWidth - 图片宽度(像素),用于边界检查和完整度计算
|
|
50
|
-
* @param imageHeight - 图片高度(像素),用于边界检查和完整度计算
|
|
40
|
+
* @param grayFrame - OpenCV Mat 对象,包含灰度图像数据(已ROI裁剪)
|
|
51
41
|
* @param config - 检测配置对象,包含:
|
|
52
|
-
* -
|
|
53
|
-
* -
|
|
54
|
-
* - min_laplacian_variance: 拉普拉斯方差最小阈值
|
|
55
|
-
* - min_gradient_sharpness: 梯度清晰度最小阈值
|
|
42
|
+
* - min_laplacian_variance: 拉普拉斯方差最小阈值(默认 40)
|
|
43
|
+
* - min_gradient_sharpness: 梯度清晰度最小阈值(默认 0.15)
|
|
56
44
|
* @param threshold - 综合质量评分阈值 (0-1),大于等于此值判定为通过
|
|
57
45
|
* @returns 综合质量检测结果,包含:
|
|
58
46
|
* - passed: 是否通过质量检测
|
|
59
47
|
* - score: 综合质量评分 (0-1)
|
|
60
|
-
* -
|
|
48
|
+
* - metrics: 各维度详细指标(拉普拉斯方差、梯度清晰度、综合质量)
|
|
61
49
|
* - blurReasons: 清晰度不通过原因列表
|
|
62
|
-
* - metrics: 各维度详细指标(完整度、拉普拉斯方差、梯度清晰度、综合质量)
|
|
63
50
|
* - suggestions: 改进建议列表
|
|
64
51
|
*/
|
|
65
|
-
export declare function calcImageQuality(cv: any,
|
|
52
|
+
export declare function calcImageQuality(cv: any, grayFrame: any, config: ImageQualityFeatures, threshold: number): ImageQualityResult;
|
|
66
53
|
//# sourceMappingURL=image-quality-calculator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"image-quality-calculator.d.ts","sourceRoot":"","sources":["../../src/image-quality-calculator.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"image-quality-calculator.d.ts","sourceRoot":"","sources":["../../src/image-quality-calculator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAoC9C;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;IACb,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,OAAO,CAAA;IACf,WAAW,EAAE,MAAM,CAAA;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAEjC,MAAM,EAAE,OAAO,CAAA;IAEf,KAAK,EAAE,MAAM,CAAA;IAEb,mBAAmB,EAAE,MAAM,EAAE,CAAA;IAC7B,WAAW,EAAE,MAAM,EAAE,CAAA;IAErB,OAAO,EAAE;QACP,YAAY,EAAE,mBAAmB,CAAA;QACjC,iBAAiB,EAAE,mBAAmB,CAAA;QACtC,iBAAiB,EAAE,mBAAmB,CAAA;QACtC,cAAc,EAAE,mBAAmB,CAAA;KACpC,CAAA;IAED,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;CACvB;AAID;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,CAC9B,EAAE,EAAE,GAAG,EACP,SAAS,EAAE,GAAG,EACd,MAAM,EAAE,oBAAoB,EAC5B,SAAS,EAAE,MAAM,GAChB,kBAAkB,CAkFpB"}
|