更改 Face-api.js 地标点颜色

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

这是我的代码,我想更改 pointColor 和 lineColor 但我不知道如何? 我正在使用 fast-api.js 库,但没有找到任何具有自定义地标样式的示例。

export const drawResults = async (image, canvas, results, type) => {
      if (image && canvas && results) {
        const imgSize = image.getBoundingClientRect();
        const displaySize = { width: imgSize.width, height: imgSize.height };
        faceapi.matchDimensions(canvas, displaySize);
        canvas.getContext('2d').clearRect(0, 0, canvas.width, canvas.height);
        const resizedDetections = faceapi.resizeResults(results, displaySize);
    
        switch (type) {
          case 'landmarks':
            faceapi.draw.drawFaceLandmarks(canvas, resizedDetections);
            break;
          case 'expressions':
            faceapi.draw.drawFaceExpressions(canvas, resizedDetections);
            break;
          case 'box':
            faceapi.draw.drawDetections(canvas, resizedDetections);
            break;
          case 'boxLandmarks':
            faceapi.draw.drawDetections(canvas, resizedDetections);
            faceapi.draw.drawFaceExpressions(canvas, resizedDetections);
            faceapi.draw.drawFaceLandmarks(canvas, resizedDetections);
            break;
          default:
            break;
        }
      }
    };
    ```
javascript html css reactjs face-api
1个回答
0
投票

利用faceapi中的drawFaceLandmarks函数进行自定义绘制线、线条颜色等

 // Custom options for drawing landmarks
    const drawOptions = {
      drawLines: true, // Enable drawing lines between points
      lineColor: 'red', // Custom line color
      pointColor: 'blue', // Custom point color
    };

在drawfacelandmark函数中传递drawOptions对象 喜欢

faceapi.draw.drawFaceLandmarks(canvas, resizedDetections, drawOptions);

© www.soinside.com 2019 - 2024. All rights reserved.