xxxxxxxxxx
44
// this sketch allows you to use your nose to draw on the screen
// the closer your nose is to the camera, the thicker the stroke
// we find the distance of nose to screen by checking the distance between your eyes
let poseNet;
let myVideo;
let myResults;
function setup() {
myVideo = createCapture(VIDEO);
myVideo.hide()
createCanvas(640, 480);
poseNet = ml5.poseNet(myVideo, gotModel);
noStroke();
fill(155, 255, 10)
}
function gotModel(){
poseNet.on('pose', gotResults);
}
function gotResults(results){
if(results) {
myResults = results;
//console.log(myResults)
}
}
function draw() {
//image(myVideo, 0, 0, width, height);
if (myResults && myResults[0]){
const nose = myResults[0].pose.nose;
//ellipse(nose.x, nose.y, 15, 15)
const leftEye = myResults[0].pose.leftEye;
const rightEye = myResults[0].pose.rightEye;
const size = dist(rightEye.x, rightEye.y,leftEye.x, leftEye.y);
//fill(random() * 255, random() * 255, random() * 255) // ranbow fill
fill(random() * 255, 255, 10)
ellipse(nose.x, nose.y, size/4, size/4);
}
}