SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5.   <title>poseNet</title>
  6.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7.   <!-- p5 -->
  8.   <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/p5.min.js"></script>
  9.   <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.dom.min.js"></script>
  10.   <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.9.0/addons/p5.sound.min.js"></script>
  11.   <!-- ml5 -->
  12.   <script src="https://unpkg.com/ml5@0.4.3/dist/ml5.min.js"></script>
  13. </head>
  14. <style>
  15.   body {
  16.     display: flex;
  17.     align-items: center;
  18.     justify-content: center;
  19.     margin: 0;
  20.     padding: 0;
  21.   }
  22. </style>
  23.  
  24. <body>
  25.   <script>
  26.     let video;
  27.     let poseNet;
  28.     let pose;
  29.     let skeleton;
  30.  
  31.     function setup() {
  32.       createCanvas(640, 480);
  33.       video = createCapture(VIDEO);
  34.       video.hide();
  35.       poseNet = ml5.poseNet(video, modelLoaded);
  36.       poseNet.on('pose', gotPoses);
  37.     }
  38.  
  39.     const gotPoses = poses => {
  40.       if (poses.length > 0) {
  41.         pose = poses[0].pose;
  42.         skeleton = poses[0].skeleton;
  43.       }
  44.     }
  45.  
  46.     const modelLoaded = () => {
  47.       console.log('poseNet ready')
  48.     }
  49.  
  50.     function draw() {
  51.       image(video, 0, 0);
  52.  
  53.       if (pose) {
  54.         for (let i = 0; i < pose.keypoints.length; i++) {
  55.           let x = pose.keypoints[i].position.x;
  56.           let y = pose.keypoints[i].position.y;
  57.           fill(0,255,0);
  58.           ellipse(x,y,16,16);
  59.         }
  60.  
  61.         for (let j = 0; j < skeleton.length; j++) {
  62.           let a = skeleton[j][0];
  63.           let b = skeleton[j][1];
  64.           strokeWeight(2);
  65.           stroke(255);
  66.           line(a.position.x, a.position.y, b.position.x, b.position.y);
  67.         }
  68.       }
  69.     }
  70.   </script>
  71. </body>
  72. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top