xxxxxxxxxx
116
//when you say how much can you see two big red eyes should appear
//when you say edo tensei two yellow with purple eyes should appear
//when you say ora a hat should appear
// all variables and lables
let video;
let poseNet;
let pose;
let classifier;
let label = "listening";
let soundModelURL = 'https://teachablemachine.withgoogle.com/models/PdIIEQvv-/model.json';
let shownImageSet = 0;
// preload function so that the code runs smoother with large external files
function preload(){
img1 =loadImage('pics/Sharingan_Triple.png');
img2 =loadImage('pics/Untitled-5.jpg');
img3 = loadImage('pics/orochimaruright.png');
img4 = loadImage('pics/orochimaruleft.png');
img5 =loadImage('pics/Untitled-9.png');
classifier = ml5.soundClassifier(soundModelURL);
}
function setup() {
createCanvas(640, 480);
video = createCapture(VIDEO);
video.hide();
poseNet = ml5.poseNet(video, modelLoaded);
poseNet.on('pose', gotPoses);
classifier.classify(gotResult);
}
// to load the pre-trained poseNet model
function gotPoses(poses) {
if (poses.length > 0) {
pose = poses[0].pose;
}
}
//when it loads it writes on console poseNet ready
function modelLoaded() {
console.log('poseNet ready');
}
// the images used for the filters
function drawImages() {
// Select image set based on pose + label
if (pose) {
if (label == "HowMuchCanYouSee") {
shownImageSet = 1;
}
if (label == "Orochimaru") {
shownImageSet = 2;
}
if (label == "Jotaro") {
shownImageSet = 3;
}
}
if (shownImageSet) {
//parameters used for eache filter so that they sit on the eyes correctly
// with all its variables for each (d= the distance for the filter to scale correctly with how far one is standing from the camera) / ( eyeR= the x and y possition of the Right eye) / (eyeL= the x and y possition of the left eye)
const eyeR = pose.rightEye;
const eyeL = pose.leftEye;
const d = dist(eyeR.x, eyeR.y, eyeL.x, eyeL.y);
if (shownImageSet == 1) {
image(img1, eyeL.x - d / 2, eyeL.y - d / 2, d, d);
image(img1, eyeR.x - d / 2, eyeR.y - d / 2, d, d);
}
else if (shownImageSet == 2) {
image(img4, eyeL.x - d / 1.5, eyeL.y - d / 1.5, (d * 3) / 2, (d * 3) / 2);
image(img3, eyeR.x - d / 1.2, eyeR.y - d / 1.5, (d * 3) / 2, (d * 3) / 2);
}
else if (shownImageSet == 3) {
image(img5, pose.nose.x - d , pose.nose.y - d*3, d+100,d+100);
}
}
}
//show the video,the images and the labels
function draw() {
image(video, 0, 0);
drawImages();
fill(255, 0, 0);
textSize(24);
textAlign(CENTER, CENTER);
text(label, 118, 15);
}
// if theres an error print the word "error"in the console
// print the word "lablein" the console so thet we know what lable is active
//
function gotResult(error, results) {
if (error) {
console.error(error);
return;
}
label = results[0].label;
}