首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否可以将视频隐藏在ml5.js中,但保持手的姿势点?

是否可以将视频隐藏在ml5.js中,但保持手的姿势点?
EN

Stack Overflow用户
提问于 2022-02-20 17:47:29
回答 1查看 156关注 0票数 2

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

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

代码语言:javascript
复制
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);
    }
  }
}
EN

回答 1

Stack Overflow用户

发布于 2022-02-20 18:56:38

是的,只需停止将它绘制到画布上,然后添加一个对background的调用来填充画布。

代码语言:javascript
复制
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

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71197097

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档