Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Forks of this sketch will become the forks of "ml5v2_Hand_2024".
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
A fork of ml5v2_Hand_2024 by Golan Levin
CC Attribution NonCommercial ShareAlike
ml5-HandPuppet-2025
Levin
xxxxxxxxxx
// Makes a simple puppet using hand landmarks.
// Uses p5.js v.1.11.3, and ml5 v.1.2.1 (2024):
// https://unpkg.com/ml5@1/dist/ml5.js
//
// If you'd like to use microphone input, this sketch includes:
// https://cdn.jsdelivr.net/npm/p5.sound@0.1.0
// See this example to understand how to access sound:
// https://openprocessing.org/sketch/2189445
let myWebcam;
let myHandTracker;
let hands = [];
let trackerOptions = { maxHands: 1, flipHorizontal: true };
let webcamAlpha = 60; // reduce this to make video transparent
//----------------------------
function setup() {
createCanvas(640, 480);
initializeWebcamAndHandTracker();
}
//----------------------------
function preload(){
preloadHandTracker();
}
//----------------------------
function draw() {
background('LightCyan');
drawWebcamVideo();
// drawAllHandPoints();
drawPuppet();
}
function drawPuppet(){
if (hands.length > 0){ // keep this!
let pts = hands[0].keypoints;
strokeWeight(20);
stroke('Indigo');
fill('LavenderBlush');
// Draw the head and ears
let bunnyHeadY = pts[WRIST].y - 80;
let bunnyHeadX = pts[WRIST].x;
line(pts[INDEX_TIP].x, pts[INDEX_TIP].y, bunnyHeadX, bunnyHeadY); // ears!
line(pts[MIDDLE_TIP].x, pts[MIDDLE_TIP].y, bunnyHeadX, bunnyHeadY);
ellipse(bunnyHeadX, bunnyHeadY + 200, 160, 400);
circle(bunnyHeadX, bunnyHeadY, 160);
// Draw the eyes
strokeWeight(10);
fill('White');
circle(bunnyHeadX - 25, bunnyHeadY, 60);
circle(bunnyHeadX + 25, bunnyHeadY, 60);
fill('Indigo');
circle(bunnyHeadX - 25, bunnyHeadY, 10);
circle(bunnyHeadX + 25, bunnyHeadY, 10);
} else {
noStroke();
fill('black');
text("hold up a hand", 20,30);
}
}
//----------------------------
function drawAllHandPoints(){
// Draw all the tracked hand points
noStroke();
fill('black');
for (let i = 0; i < hands.length; i++) {
let hand = hands[i];
let keypoints = hand.keypoints; // also available: keypoints3D
for (let j = 0; j < keypoints.length; j++) {
let aKeypoint = keypoints[j];
circle(aKeypoint.x, aKeypoint.y, 3);
}
}
}
//==============================================================
// DON'T CHANGE ANYTHING BELOW THIS LINE.
//
//----------------------------
function initializeWebcamAndHandTracker(){
// Create the webcam video, and start detecting hands:
myWebcam = createCapture(VIDEO);
myWebcam.size(640, 480).hide();
myHandTracker.detectStart(myWebcam, gotHands);
}
//----------------------------
function drawWebcamVideo(){
// Draw the webcam video
push();
if (trackerOptions.flipHorizontal){
translate(myWebcam.width,0);
scale(-1,1);
}
tint(255,255,255,webcamAlpha);
image(myWebcam, 0, 0, myWebcam.width, myWebcam.height);
pop();
}
//----------------------------
function preloadHandTracker() {
// Load the Handpose model.
myHandTracker = ml5.handPose(trackerOptions);
}
function gotHands(results) {
// If fresh Handpose data is received, store it.
hands = results;
}
//----------------------------
// The following hand point index labels may be useful:
const WRIST = 0;
const THUMB_CMC = 1;
const THUMB_MCP = 2;
const THUMB_IP = 3;
const THUMB_TIP = 4;
const INDEX_MCP = 5;
const INDEX_PIP = 6;
const INDEX_DIP = 7;
const INDEX_TIP = 8;
const MIDDLE_MCP = 9;
const MIDDLE_PIP = 10;
const MIDDLE_DIP = 11;
const MIDDLE_TIP = 12;
const RING_MCP = 13;
const RING_PIP = 14;
const RING_DIP = 15;
const RING_TIP = 16;
const PINKY_MCP = 17;
const PINKY_PIP = 18;
const PINKY_DIP = 19;
const PINKY_TIP = 20;
See More Shortcuts
Please verify your email to comment
Verify Email