如何使用face-api.js提取表情名称?

问题描述 投票:0回答:1

当前当我控制台登录以下代码时:(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, …}
reactjs face-detection face-api
1个回答
0
投票

你可以得到这样的结果

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 
}
© www.soinside.com 2019 - 2024. All rights reserved.