跳转至

02人体动作识别

1. p5.js 获取摄像头视频

var capture;

function setup() {
  createCanvas(320, 240);
  capture = createCapture(VIDEO);
  capture.hide();
}

function draw() {  
  push();
  translate(width,0);
  scale(-1, 1);
  image(capture, 0, 0, 320, 240);
  pop();
};
  pop();
}

2. 使用ml5.poseNet识别人体关键点。

var capture;
let poses = [];

function setup() {
  createCanvas(320, 240);
  capture = createCapture(VIDEO);
  capture.size(width, height);
  capture.hide();

  poseNet = ml5.poseNet(capture);
  poseNet.on('pose', gotpose)
}

function gotpose(results) {
  poses = results;
}

function draw() {
  push();
  translate(width, 0);
  scale(-1, 1);
  image(capture, 0, 0);
  if (poses.length) {
    drawKeypoints();
    drawSkeleton();
  }
  pop();
}

// A function to draw ellipses over the detected keypoints
function drawKeypoints() {
  // For each pose detected, loop through all the keypoints
  let pose = poses[0].pose;
  for (let j = 0; j < pose.keypoints.length; j++) {
    // A keypoint is an object describing a body part (like rightArm or leftShoulder)
    let 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);
    }
  }
}

// A function to draw the skeletons
function drawSkeleton() {
  // Loop through all the skeletons detected
  let skeleton = poses[0].skeleton;
  // For every skeleton, loop through all body connections
  for (let j = 0; j < skeleton.length; j++) {
    let partA = skeleton[j][0];
    let partB = skeleton[j][1];
    stroke(255, 0, 0);
    line(partA.position.x, partA.position.y, partB.position.x, partB.position.y);
  }
}

设置选型中,减小识别准确度可以增加识别结果数量。

  • inputResolution 输入图像分辨率,默认257,分辨率越小精度越差
  • multiplier 层数,越小精度越差

3. 识别跳绳数据

参考项目

  • 深蹲练习APP

https://colab.research.google.com/drive/1OHTsNyr3Ry_bSw8dT9s77BZsXHe7i8HR#scrollTo=uIbljMew7Wje

  • 头部歪斜检测

https://glitch.com/~false-lobe

  • 动作计数

https://github.com/samsonleegh/workout_counter

  • Python写的运动计数器

https://github.com/akshatkaush/exercise-count

回到页面顶部