Spaces:
Runtime error
Runtime error
File size: 2,446 Bytes
709edf5 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
// // Import TFJS runtime with side effects.
// import '@tensorflow/tfjs-backend-webgl';
// import * as poseDetection from '@tensorflow-models/pose-detection';
// // import 'https://cdn.jsdelivr.net/npm/@tensorflow/tfjs-backend-webgl';
// // import * as poseDetection from 'https://cdn.jsdelivr.net/npm/@tensorflow-models/pose-detection';
/*
=============
Params
=============
*/
let capture;
let font;
let detector;
let poses;
let angle = 0.0;
/*
=============
Function
=============
*/
function preload() {
}
function setup() {
createCanvas(640, 480);
capture = createCapture(VIDEO, captureLoaded);
background(255);
}
function captureLoaded() {
console.log("capture loaded...");
initModel();
}
async function initModel() {
const _model = poseDetection.SupportedModels.MoveNet;
console.log("model:", _model);
const detectorConfig = {
runtime: "tfjs", // 'mediapipe', 'tfjs'
//modelType: "lite", // 'lite', 'full', 'heavy'
};
detector = await poseDetection.createDetector(_model, detectorConfig);
}
async function getPose() {
poses = await detector.estimatePoses(capture.elt);
}
function draw() {
background(0,1);
if (detector) {
getPose();
}
drawPoseInfo();
}
function drawPoseInfo() {
noStroke();
fill(255, 0, 0, 128);
if (poses && poses.length > 0) {
for (var i = 0; i < poses.length; i++) {
for (var j = 0; j<poses[i].keypoints.length; j++) {
if (poses[i].keypoints[j].score > 0.1) {
let posX = width-int(poses[i].keypoints[j].x);
let posY = height-int(poses[i].keypoints[j].y);
//circle(posX, posY, 10);
}
}
}
stroke(255);
if (poses.length > 0) {
let l = poses[0].keypoints.length;
for (var j = 4; j<l; j++) {
for (var i = j+1; i<l; i++) {
let d = dist(int(poses[0].keypoints[i].x),
int(poses[0].keypoints[i].y),
int(poses[0].keypoints[j].x),
int(poses[0].keypoints[j].y));
if(d > 150){
line( int(poses[0].keypoints[i].x),
int(poses[0].keypoints[i].y),
int(poses[0].keypoints[j].x),
int(poses[0].keypoints[j].y));
}
}
}
}
}
}
function keyPressed() {
noLoop();
}
|