xxxxxxxxxx
47
let handpose;
let facemesh;
let video;
let handPredictions = [];
let facePredictions = [];
let pigeonEmoji = '🐦';
function setup() {
createCanvas(640, 480);
// Set up the video
video = createCapture(VIDEO);
video.size(width, height);
video.hide();
// Load Handpose model
handpose = ml5.handpose(video, () => console.log('Handpose model loaded'));
handpose.on('predict', results => handPredictions = results);
// Load Facemesh model
facemesh = ml5.facemesh(video, () => console.log('Facemesh model loaded'));
facemesh.on('predict', results => facePredictions = results);
}
function draw() {
image(video, 0, 0, width, height);
// Check if mouth is open and hand is detected
if (isMouthOpen() && handPredictions.length > 0) {
const indexFinger = handPredictions[0].annotations.indexFinger[3]; // Get index finger tip position
textSize(32);
text(pigeonEmoji, indexFinger[0], indexFinger[1]); // Draw pigeon emoji on index finger
}
}
function isMouthOpen() {
if (facePredictions.length > 0) {
// Calculate the distance between two points around the mouth
const upperLip = facePredictions[0].scaledMesh[13];
const lowerLip = facePredictions[0].scaledMesh[14];
const distance = dist(upperLip[0], upperLip[1], lowerLip[0], lowerLip[1]);
return distance > 20; // Adjust threshold as needed
}
return false;
}