@face-auth/face-detector

中文文档
0.0.6发布于 2026/03/31SEE LICENSE IN LICENSETypeScriptESM + CJS近 30 天下载 3005

Lightweight face detection for browser video streams, providing callbacks with face presence, quality guidance, and bounding boxes.

原始使用文档
文档目录17 节
  1. Installation
  2. License
  3. Support
  4. Package format
  5. Public API
  6. Classes
  7. Enums and helpers
  8. Exported types
  9. FaceVideoDetector
  10. Methods
  11. FaceImageDetector
  12. Methods
  13. Detection output (summary)
  14. FaceAdjustment reference
  15. FaceQualityWarningMetric reference
  16. Example (video)
  17. Browser support

@face-auth/face-detector

Face Auth

Version Last update Browser only

Lightweight face detection for browser video streams. Current package version: 0.0.6.

Installation

npm install @face-auth/face-detector

License

Proprietary runtime-only license. You may execute unmodified copies of the package, but modification, redistribution, sublicensing, and other reuse are not permitted. See LICENSE.

Support

Package format

  • import resolves to the package ESM bundle.
  • require resolves to the package CommonJS bundle.
  • Deep imports are not part of the supported public contract; consume the package root entrypoint only.

Public API

Classes

  • FaceVideoDetector
  • FaceImageDetector

Enums and helpers

  • FaceAdjustment
  • getInscribedCircle(...)
  • isEllipseInside(...)

Exported types

  • BoundingBox
  • Detection
  • DetectionParams
  • DetectionResult
  • ImageDetectionResult
  • FaceKeypoint
  • FacePoseMetrics
  • FaceQualityMetrics
  • FaceQualityGateResult
  • FaceQualityWarning
  • FaceQualityWarningMetric
  • QualityGateConfig

FaceVideoDetector

Creates a detector over an HTMLVideoElement and emits detection results.

import { FaceVideoDetector } from '@face-auth/face-detector';

const videoElement = document.getElementById('video') as HTMLVideoElement;
const detector = new FaceVideoDetector(videoElement);

Methods

  • startDetecting(params?: DetectionParams): Promise<void>
  • stopDetecting(): Promise<void>
  • onDetection(callback): void
  • offDetection(callback): void

onDetection callbacks receive a DetectionResult:

{
  tick: number;
  detections: Detection[];
}

FaceImageDetector

Runs face detection on a single image source.

import { FaceImageDetector } from '@face-auth/face-detector';

const imageDetector = new FaceImageDetector();
const result = await imageDetector.detect(fileOrCanvasOrImageBitmap, {
  qualityGateConfig: {
    strictShouldPass: true,
  },
});

Methods

  • detect(image: ImageBitmapSource, options?): Promise<ImageDetectionResult>

Detection output (summary)

{
  detections: Array<{
    boundingBox: {
      x: number;
      y: number;
      width: number;
      height: number;
    };
    score: number;
    keypoints: Array<{
      x: number;
      y: number;
      normalizedX: number;
      normalizedY: number;
      label?: string;
      score?: number;
    }>;
    quality: {
      shouldPass: boolean;
      faceAdjustment: 'none' | 'move_closer' | 'move_farther' | 'show_full_face' | 'turn_face_left' | 'turn_face_right' | 'tilt_head_left' | 'tilt_head_right' | 'lower_chin' | 'raise_chin' | 'improve_lighting' | 'improve_focus';
      warning: {
        metric?: string;
        measuredValue?: number;
        threshold?: number;
      } | null;
      metrics: {
        faceAreaRatio: number;
        blurVariance: number | null;
        blackClippingRatio: number | null;
        brightnessMean: number | null;
        pose: {
          rollDeg: number | null;
          yawRatio: number | null;
          pitchRatio: number | null;
        };
      };
    };
  }>;
}

For video detection, the callback payload also includes tick, the performance.now() timestamp for that processed frame.

Directional adjustments:

  • turn_face_left / turn_face_right are corrective turn hints from the current detected pose.
  • tilt_head_left / tilt_head_right are corrective roll (ear-to-shoulder) hints.

FaceAdjustment reference

faceAdjustment always returns one primary correction target.

ValueWhat correction is requested
noneNo correction needed. Capture quality is currently acceptable.
move_closerMove the face closer to the camera (face appears too small in frame).
move_fartherMove the face farther from the camera (face appears too large in frame).
show_full_faceKeep the full face visible and frontal enough so pose can be measured reliably.
turn_face_leftTurn the face slightly to the user's left to improve frontal alignment.
turn_face_rightTurn the face slightly to the user's right to improve frontal alignment.
tilt_head_leftCorrect roll by tilting the head slightly to the user's left.
tilt_head_rightCorrect roll by tilting the head slightly to the user's right.
lower_chinLower the chin slightly.
raise_chinRaise the chin slightly.
improve_lightingImprove lighting/exposure conditions on the face.
improve_focusImprove image sharpness/focus (reduce blur).

FaceQualityWarningMetric reference

When quality.warning is present, metric can be:

ValueMetric meaning
faceAreaRatioRelative face size in frame (face bounding box area / frame area).
blurVarianceSharpness proxy (Laplacian variance); low values indicate blur.
brightnessMeanAverage brightness in the sampled face region.
blackClippingRatioRatio of near-black pixels in the face region.
rollDegLateral head tilt angle in degrees (ear-to-shoulder).
yawRatioHorizontal turn/off-center pose ratio.
pitchRatioVertical chin pose ratio (up/down).

Example (video)

detector.startDetecting({ minIntervalMs: 120 });

detector.onDetection((result) => {
  const face = result.detections[0];
  if (!face) return;

  console.log(face.boundingBox);
  console.log(face.quality.shouldPass);
  console.log(face.quality.faceAdjustment);
  console.log(face.quality.warning);
  console.log(face.quality.metrics);
});

Browser support

  • Browser runtime only.
  • Requires HTMLVideoElement / ImageBitmapSource input.
  • DetectionParams.minIntervalMs defaults to 100 when omitted.

版本与发布记录

@face-auth/face-detector 共发布 6 个版本,首次发布于 2025/08/29;过去 12 个月发布了 5 个版本。

版本发布日期距今
0.0.6latest2026/03/317 个月前
0.0.52026/03/138 个月前
0.0.42026/03/128 个月前
0.0.32026/03/048 个月前
0.0.22026/03/048 个月前
0.0.12025/08/291.2 年前

关于 @face-auth/face-detector 的常见问题

@face-auth/face-detector 是什么?

Lightweight face detection for browser video streams, providing callbacks with face presence, quality guidance, and bounding boxes.

如何安装 @face-auth/face-detector?

在项目目录运行 npm install @face-auth/face-detector,或使用 pnpm add / yarn add / bun add。

@face-auth/face-detector 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@face-auth/face-detector 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@face-auth/face-detector 可以商用吗?

@face-auth/face-detector 使用 SEE LICENSE IN LICENSE 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@face-auth/face-detector 的下载量有多少?

根据 npm 官方下载统计,@face-auth/face-detector 在 2026/10/14 – 2026/11/12 这 30 天内被下载 3,005 次,日均约 100 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@face-auth/face-detector 还在维护吗?

最新版本 0.0.6 发布于 2026/03/31(7 个月前);至今共发布 6 个版本,其中过去 12 个月发布了 5 个;首次发布于 2025/08/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。