如何使用face-api.js提取表达式名称



当前当我控制台登录以下代码时:(API Github(对于人脸表情检测,我有以下代码行:

const detections = await faceapi.detectAllFaces(videoRef.current, new faceapi.TinyFaceDetectorOptions()).withFaceLandmarks().withFaceExpressions()

当我控制台记录检测变量时,它会给出以下结果:

Array(1)0: alignedRect: FaceDetection {_imageDims: Dimensions, _score: 0.8277419589060608,_classScore: 0.8277419589060608, _className: "", _box: Box}detection: FaceDetection {_imageDims: Dimensions, _score: 0.8277419589060608, _classScore: 0.8277419589060608,_className: "", _box: Box}expressions: FaceExpressions {neutral: 0.9946907162666321, happy: 0.005221708677709103, sad: 0.000022168851501191966, angry: 0.000003129790229650098, fearful:1.3060009962373442e-7, …}landmarks: FaceLandmarks68 {_imgDims: Dimensions, _shift: Point,_positions: Array(68)}unshiftedLandmarks: FaceLandmarks68 {_imgDims: Dimensions, _shift: Point, _positions: Array(68)}__proto__: Objectlength: 1__proto__: Array(0)

现在我想使用这些表达式,并对每个表达式名称的值应用max函数。但我无法访问它。如何访问这些表达式以进一步使用?

expressions: FaceExpressions {neutral: 0.9946907162666321, happy: 0.005221708677709103, sad: 0.000022168851501191966, angry: 0.000003129790229650098, fearful: 1.3060009962373442e-7, …}

您可以得到这样的结果

const detections = await faceapi.detectAllFaces(videoRef.current, new faceapi.TinyFaceDetectorOptions()).withFaceLandmarks().withFaceExpressions()
if (detections ) {
const dims = faceapi.matchDimensions(CANVAS_DISPLAY, OGVIDEO, true)
const resizedResult = faceapi.resizeResults(detections , dims)
const minConfidence = 0.6
let finalResult = Object.values(detections.expressions)// this is the expressions 
}

最新更新