“PoseNet-ML5” by Theresa
https://openprocessing.org/sketch/2093822
License CreativeCommons Attribution NonCommercial ShareAlike
https://creativecommons.org/licenses/by-nc-sa/3.0
{{filePath}}
{{width}} x {{height}}
Report Sketch
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.
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!
CC Attribution NonCommercial ShareAlike
PoseNet-ML5
xxxxxxxxxx
//https://github.com/ml5js/ml5-library/blob/main/examples/p5js/PoseNet/PoseNet_webcam/sketch.js
let video;
let poseNet;
let poses = [];
let table;
let tpoints = "";
let tA = "";
let tB = "";
function setup() {
createCanvas(640, 480);
video = createCapture(VIDEO);
video.size(width, height);
frameRate(1);
table = new p5.Table();
table.addColumn('time');
table.addColumn('points');
table.addColumn('partA');
table.addColumn('partB');
// Create a new poseNet method with a single detection
poseNet = ml5.poseNet(video, modelReady);
// This sets up an event that fills the global variable "poses"
// with an array every time new poses are detected
poseNet.on("pose", function(results) {
poses = results;
});
// Hide the video element, and just show the canvas
video.hide();
}
function modelReady() {
select("#status").html("Model Loaded");
}
function draw() {
image(video, 0, 0, width, height);
// We can call both functions to draw all keypoints and the skeletons
//console.log(tpoints);
let newRow = table.addRow();
console.log(tpoints);
newRow.setString('time', Date());
newRow.setString('points', tpoints);
newRow.setString('partA', tA);
newRow.setString('partB', tB);
tpoints = "";
tA = "&";
tB = "&";
drawKeypoints();
drawSkeleton();
}
// A function to draw ellipses over the detected keypoints
function drawKeypoints() {
// Loop through all the poses detected
for (let i = 0; i < poses.length; i += 1) {
// For each pose detected, loop through all the keypoints
const pose = poses[i].pose;
for (let j = 0; j < pose.keypoints.length; j += 1) {
// A keypoint is an object describing a body part (like rightArm or leftShoulder)
const keypoint = pose.keypoints[j];
// Only draw an ellipse is the pose probability is bigger than 0.2
if (keypoint.score > 0.2) {
fill(255, 0, 0);
noStroke();
ellipse(keypoint.position.x, keypoint.position.y, 10, 10);
tpoints += (keypoint.position.x + "#" + keypoint.position.y + ",");
}
}
}
}
// A function to draw the skeletons
function drawSkeleton() {
// Loop through all the skeletons detected
for (let i = 0; i < poses.length; i += 1) {
const skeleton = poses[i].skeleton;
// For every skeleton, loop through all body connections
for (let j = 0; j < skeleton.length; j += 1) {
const partA = skeleton[j][0];
const partB = skeleton[j][1];
stroke(255, 0, 0);
line(partA.position.x, partA.position.y, partB.position.x, partB.position.y);
tA += (partA.position.x + "#" + partA.position.y + ",");
tB += (partB.position.x + "#" + partB.position.y + ",");
}
}
}
function keyPressed() {
if (key == "c") {
save(table, 'PoseNet.csv');
}
}
See More Shortcuts
Please verify your email to comment
Verify Email