xxxxxxxxxx
87
// Made during @computational_mama's workshop:
// "Fingerp(AI)nting with Words"
// organised by AIxDesign Community
let webcam;
let handpose;
let hands;
let modelLoaded = false;
const options = {
flip : true
}
const words = [
["Algernon", "Ernest", "Jack", "Lady Brecknell", "Gwendolen", "Cecily", "Lain"],
["is", "had", "made", "mocked", "punched", "ate", "cooked"],
["a lot of", "no", "some"],
["lonely", "happy", "depressed", "narcissistic", "egomaniac"],
["sandwiches", "chickens", "emus", "turkeys"]
];
let sentence = []
function initSentence() {
for (let i = 0; i < words.length; i++) {
sentence.push(random(words[i]));
}
}
function setup() {
createCanvas(640, 480);
initSentence()
// console.log(sentence)
webcam = createCapture(VIDEO)
webcam.size(640, 480);
webcam.hide();
const options = {
flipHorizontal: true, // boolean value for if the video should be flipped, defaults to false
// maxContinuousChecks: Infinity, // How many frames to go without running the bounding box detector. Defaults to infinity, but try a lower value if the detector is consistently producing bad predictions.
// detectionConfidence: 0.8, // Threshold for discarding a prediction. Defaults to 0.8.
};
handpose = ml5.handpose(webcam, options, () => {
console.log("Model loaded");
modelLoaded = true;
});
handpose.on("hand", results => {
hands = results
})
}
function draw() {
// background(220);
if (!modelLoaded) return;
const flippedImage = ml5.flipImage(webcam);
image(flippedImage, 0, 0, webcam.width, webcam.height);
drawKeypoints()
}
function drawKeypoints() {
for (let i = 0; i < hands.length; i++) {
// const hand = hands[i]
// for (let j = 0; j < hand.landmarks.length; j++) {
// const keypoint = hand.landmarks[j];
// ellipse(keypoint[0], keypoint[1], 10);
// }
// }
stroke(255)
let thumb = { x : hands[i].landmarks[4][0], y : hands[i].landmarks[4][1] }
let index = { x : hands[i].landmarks[8][0], y : hands[i].landmarks[8][1] }
let middle = { x : hands[i].landmarks[12][0], y : hands[i].landmarks[12][1] }
let ring = { x : hands[i].landmarks[16][0], y : hands[i].landmarks[16][1] }
let little = { x : hands[i].landmarks[20][0], y : hands[i].landmarks[20][1] }
textSize(18)
text(sentence[0], thumb.x, thumb.y)
text(sentence[1], index.x, index.y)
text(sentence[2], middle.x, middle.y)
text(sentence[3], ring.x, ring.y)
text(sentence[4], little.x, little.y)
}
}