fix(camera): relax initial frontal face recognition

This commit is contained in:
xsl
2026-10-16 15:27:36 +08:00
parent 8365ef459f
commit 30c90f8df5
5 changed files with 35 additions and 12 deletions
+9 -4
View File
@@ -607,7 +607,7 @@
var img = new Image();
img.onload = function () {
faceapi
.detectAllFaces(img, new faceapi.TinyFaceDetectorOptions({ inputSize: DETECT_INPUT_SIZE, scoreThreshold: DETECT_SCORE }))
.detectAllFaces(img, new faceapi.TinyFaceDetectorOptions({ inputSize: DETECT_INPUT_SIZE, scoreThreshold: CaptureQuality.scoreThreshold(target) }))
.withFaceLandmarks()
.then(function (faces) {
var d = faces[0], box = d && d.detection.box;
@@ -768,8 +768,8 @@
var MODEL_URL = 'vendor/faceapi/models';
var DETECT_INTERVAL = 150; // 检测帧间隔(ms)
var DETECT_INPUT_SIZE = 416; // tinyFaceDetector 输入尺寸:320 下正脸置信度仅 0.67 且框偏松,416 置信度 ~0.99 框更准(CPU 端略慢,移动端 GPU 无感)
var DETECT_SCORE = CaptureQuality.config.score;
var MISS_FRAMES_MAX = 3; // 连续漏检 ≥3 帧(~450ms)才报「未检测到人脸」,容忍单帧抖动
var FRONT_MISS_FRAMES_MAX = 6; // 正面首次发现人脸前,多给相机对焦/曝光几次检测机会。
var NO_PROGRESS_MS = 12000; // 单步超过该时长仍未抓拍→浮出调整提示
var PREVIEW_SCALE = 1; // 与 CSS #cam-video 铺满预览一致,镜像只改变方向
@@ -860,6 +860,7 @@
holdState = null;
resetAngleHaptic();
missFrames = 0;
frontFaceSeen = false;
oppFrames = 0;
lastHint = '';
clearTimeout(nudgeTimer);
@@ -913,7 +914,7 @@
if (shutterLock || capturing || !camLive) return Promise.resolve(); // 抓帧/流程推进中不判姿态
var step = camStep, seq = camSeq, generation = detGeneration; // 旧镜头推理结果不能污染新镜头
return faceapi
.detectAllFaces(camVideo, new faceapi.TinyFaceDetectorOptions({ inputSize: DETECT_INPUT_SIZE, scoreThreshold: DETECT_SCORE }))
.detectAllFaces(camVideo, new faceapi.TinyFaceDetectorOptions({ inputSize: DETECT_INPUT_SIZE, scoreThreshold: CaptureQuality.scoreThreshold(CAM_STEPS[step].target) }))
.withFaceLandmarks()
.then(function (d) {
if (step !== camStep || seq !== camSeq || generation !== detGeneration) return;
@@ -941,6 +942,7 @@
} catch (e) { return null; }
}
var missFrames = 0; // 连续漏检帧计数:单帧抖动不报「未检测到人脸」
var frontFaceSeen = false;
/* camera-haptic-pure-begin */
function captureHaptic(nav) {
// Unsupported/blocked vibration must never interrupt automatic capture.
@@ -976,7 +978,10 @@
if (Array.isArray(d)) d = d[0];
var hint = '', ok = false;
missFrames = d ? 0 : missFrames + 1;
var hasFace = !!d, noFace = !hasFace && missFrames >= MISS_FRAMES_MAX;
var hasFace = !!d;
if (hasFace && CAM_STEPS[camStep].target === 'front') frontFaceSeen = true;
var missLimit = CAM_STEPS[camStep].target === 'front' && !frontFaceSeen ? FRONT_MISS_FRAMES_MAX : MISS_FRAMES_MAX;
var noFace = !hasFace && missFrames >= missLimit;
if (noFace) {
hint = '未检测到人脸';
} else if (!hasFace) {