@ face-auth/ 面部检测器
浏览器视频流的轻量级面部检测.
当前软件包版本 : 0.0.6。 。 。 .
安装
npm install @face-auth/face-detector
许可证
专有跑时专用许可证. 您可以执行软件包的未修改副本,
但不允许修改、再分配、分许可证和其他再利用.
见 LICENSE。 。 。 .
支助
- 主页 :
https://www.face-auth.me/ - 支助:
[email protected]
软件包格式
import决定一揽子无害环境管理捆绑.require解析到软件包 CommunityJS 捆绑.- 深度进口不是所支持的公共合同的一部分;只消费包的根入点.
公共 API
类
FaceVideoDetectorFaceImageDetector
数字和助手
FaceAdjustmentgetInscribedCircle(...)isEllipseInside(...)
导出类型
BoundingBoxDetectionDetectionParamsDetectionResultImageDetectionResultFaceKeypointFacePoseMetricsFaceQualityMetricsFaceQualityGateResultFaceQualityWarningFaceQualityWarningMetricQualityGateConfig
FaceVideoDetector
创建一个检测器 HTMLVideoElement 并发出检测结果.
import { FaceVideoDetector } from '@face-auth/face-detector';
const videoElement = document.getElementById('video') as HTMLVideoElement;
const detector = new FaceVideoDetector(videoElement);
方法
startDetecting(params?: DetectionParams): Promise<void>stopDetecting(): Promise<void>onDetection(callback): voidoffDetection(callback): void
onDetection 回调收到一个 DetectionResult数字 :
{
tick: number;
detections: Detection[];
}
FaceImageDetector
在单一图像源上运行面相检测.
import { FaceImageDetector } from '@face-auth/face-detector';
const imageDetector = new FaceImageDetector();
const result = await imageDetector.detect(fileOrCanvasOrImageBitmap, {
qualityGateConfig: {
strictShouldPass: true,
},
});
方法
detect(image: ImageBitmapSource, options?): Promise<ImageDetectionResult>
检测输出( 摘要)
{
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;
};
};
};
}>;
}
对于视频探测,回调有效载荷还包括: tick,则 performance.now() 这个处理过的相框的时标.
方向调整:
turn_face_left编号 :turn_face_right是当前检测到的姿势的正向转动提示.tilt_head_left编号 :tilt_head_right是修正卷(从头到肩)提示.
FaceAdjustment 参考文献
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 | 改进图像锐度/ 焦点( 减少模糊度) . |
FaceQualityWarningMetric 参考文献
何时 quality.warning 在场, metric 可为:
| 数值 | 计量意义 |
|---|---|
faceAreaRatio | 相框中的相对面相大小( N)face bounding box area / frame area) (中文(简体) ). |
blurVariance | 锐度代理(拉普拉西安差异);低值表示模糊. |
brightnessMean | 抽样面部区域的平均亮度. |
blackClippingRatio | 面相区域近黑像素比例. |
rollDeg | 平面头向倾斜角以度为单位(相接相接). |
yawRatio | 水平转出/转出中心摆出比例. |
pitchRatio | 垂直下巴姿势比(上下). |
示例(视频)
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);
});
浏览器支持
- 仅浏览器运行时间 .
- 要求数
HTMLVideoElement编号 :ImageBitmapSource输入. DetectionParams.minIntervalMs默认为100当省略时.