在基于 JavaScript 的面部标志检测中查找所有点的坐标

Posted

技术标签:

【中文标题】在基于 JavaScript 的面部标志检测中查找所有点的坐标【英文标题】:Finding co-ordinates of all points in JavaScript Based facial landmark detection 【发布时间】: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)
)

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

【问题讨论】:

【参考方案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)
)

【讨论】:

以上是关于在基于 JavaScript 的面部标志检测中查找所有点的坐标的主要内容,如果未能解决你的问题,请参考以下文章

人脸检测进阶:更快的5点面部标志检测器

无法使用 OpenCV2 检测面部标志

使用面部标志检测的numpy数组创建一个文本文件。?

图像处理中面部标志点的归一化

给定 dlib 的 68 点面部标志,确定它们有多好

人脸检测进阶:使用 dlibOpenCV 和 Python 检测眼睛鼻子嘴唇和下巴等面部五官