【问题标题】:Finding co-ordinates of all points in JavaScript Based facial landmark detection在基于 JavaScript 的面部标志检测中查找所有点的坐标
【发布时间】:2020-11-07 01:59:00
【问题描述】:

我必须使用 JavaScript 编程语言检测面部标志。为此,我看过this 视频教程。此外,我能够成功执行at 提供的视频代码。现在我已经显示了每个面部标志点的坐标值。我有以下用于面部标志检测的代码:

video.addEventListener('play', () => {
  const canvas = faceapi.createCanvasFromMedia(video)
  document.body.append(canvas)
  const displaySize = { width: video.width, height: video.height }
  faceapi.matchDimensions(canvas, displaySize)
  setInterval(async () => {
    const detections = await faceapi.detectAllFaces(video, new faceapi.TinyFaceDetectorOptions()).withFaceLandmarks().withFaceExpressions()
    const resizedDetections = faceapi.resizeResults(detections, displaySize)
    canvas.getContext('2d').clearRect(0, 0, canvas.width, canvas.height)
    faceapi.draw.drawDetections(canvas, resizedDetections)
    faceapi.draw.drawFaceLandmarks(canvas, resizedDetections)
    faceapi.draw.drawFaceExpressions(canvas, resizedDetections)
  }, 100)
})

请建议我应该怎么做才能访问面部标志点的坐标。

【问题讨论】:

    标签: javascript facial-landmark-alignment


    【解决方案1】:

    您可以尝试使用此代码来获取调整后尺寸的地标:

    video.addEventListener('play', () => {
      const canvas = faceapi.createCanvasFromMedia(video)
      document.body.append(canvas)
      const displaySize = { width: video.width, height: video.height }
      faceapi.matchDimensions(canvas, displaySize)
      setInterval(async () => {
        const detections = await faceapi.detectAllFaces(video, new faceapi.TinyFaceDetectorOptions()).withFaceLandmarks()
        const resizedDetections = faceapi.resizeResults(detections, displaySize)
        canvas.getContext('2d').clearRect(0, 0, canvas.width, canvas.height)
      
       //parsing the landmarks correctly
        var landmarks = resizedDetections[0]['landmarks']._positions;
    
    
        //adding canvas to draw over the face
        var ctx = canvas.getContext("2d");
    
    
        //looping over landmarks to draw the canvas
        for (var i = 0; i < landmarks.length; i++) {
          var x_val = landmarks[i]._x;
          var y_val = landmarks[i]._y;
          ctx.beginPath();
          console.log(x_val);
          console.log(y_val);
          ctx.arc(x_val, y_val, 2, 0, Math.PI*2, false);
          ctx.fillStyle = "green";
          ctx.fill();
          ctx.closePath();
        }
        
      
      }, 100)
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-17
      • 1970-01-01
      相关资源
      最近更新 更多