2

I am trying to hide the video (webcam in this case) but keep the detected points of the hand. I have tried different methods, but I am unsuccessful so far. I appreciate the help.

Main code (below) from ml5.js can be found and tested live here: 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);
    }
  }
}
ibib
  • 109
  • 5

1 Answers1

2

Yes, just stop drawing it to the canvas, and add a call to background to fill the canvas.

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

Samathingamajig
  • 11,839
  • 3
  • 12
  • 34
  • Thank you! It worked well. I was wondering if you know how I can number a point list in p5.js. I have a cloud of prediction points that I want to know their indexes. Any idea on how that is possible? Thank you. – ibib Feb 21 '22 at 04:35