1

我试图隐藏视频(在这种情况下为网络摄像头),但保留检测到的手点。我尝试了不同的方法,但到目前为止我都不成功。我很感激帮助。

来自 ml5.js 的主要代码(如下)可以在这里找到和测试: https ://editor.p5js.org/ml5/sketches/Handpose_Webcam

let handpose;
let video;
let predictions = [];

function setup() {
  createCanvas(640, 480);
  video = createCapture(VIDEO);
  video.size(width, height);

  handpose = ml5.handpose(video, modelReady);

  // This sets up an event that fills the global variable "predictions"
  // with an array every time new hand poses are detected
  handpose.on("predict", results => {
    predictions = results;
  });

  // Hide the video element, and just show the canvas
  video.hide();
}

function modelReady() {
  console.log("Model ready!");
}

function draw() {
  image(video, 0, 0, width, height);

  // We can call both functions to draw all keypoints and the skeletons
  drawKeypoints();
}

// A function to draw ellipses over the detected keypoints
function drawKeypoints() {
  for (let i = 0; i < predictions.length; i += 1) {
    const prediction = predictions[i];
    for (let j = 0; j < prediction.landmarks.length; j += 1) {
      const keypoint = prediction.landmarks[j];
      fill(0, 255, 0);
      noStroke();
      ellipse(keypoint[0], keypoint[1], 10, 10);
    }
  }
}
4

1 回答 1

1

是的,只需停止将其绘制到画布上,然后添加background对填充画布的调用即可。

function draw() {
  // image(video, 0, 0, width, height); // <- just delete this line
  background(255);

  // We can call both functions to draw all keypoints and the skeletons
  drawKeypoints();
}

https://editor.p5js.org/Samathingamajig/sketches/BV_kqU0Ik

于 2022-02-20T18:56:38.687 回答