browser_client/examples/example4_posenet_curves_simple/sketch.js
// A function to mirror the pose for testing with one person
A function to mirror the pose for testing with one person
A function to mirror the pose for testing with one person
function mirrorSkeleton(skeleton) {
  let mirroredParts = [];
  if (skeleton.length < 1) return;
  for (let i = 0; i < skeleton.length; i++) {
    const jointA = skeleton[i][0];
    const jointB = skeleton[i][1];
    const jointAMirrored = mirroredParts.includes(jointA.part);
    if (!jointAMirrored) {
      jointA.position.x = width - jointA.position.x;
    }
    const jointBMirrored = mirroredParts.includes(jointB.part);
    if (!jointBMirrored) {
      jointB.position.x = width - jointB.position.x;
    }
    mirroredParts.push(jointA.part);
    mirroredParts.push(jointB.part);
  }
}
function mirrorSkeleton ( skeleton ) { let mirroredParts = [ ] ; if ( skeleton . length < 1 ) return ; for ( let i = 0 ; i < skeleton . length ; i ++ ) { const jointA = skeleton [ i ] [ 0 ] ; const jointB = skeleton [ i ] [ 1 ] ; const jointAMirrored = mirroredParts . includes ( jointA . part ) ; if ( ! jointAMirrored ) { jointA . position . x = width - jointA . position . x ; } const jointBMirrored = mirroredParts . includes ( jointB . part ) ; if ( ! jointBMirrored ) { jointB . position . x = width - jointB . position . x ; } mirroredParts . push ( jointA . part ) ; mirroredParts . push ( jointB . part ) ; } }
A function to mirror the pose for testing with one person
A function to mirror the pose for testing with one person
// We need to keep track of which parts are mirrored because // posenet duplicates parts within the pose object // Check that there are parts, if not return // Loop through all skeleton connections // Get the joints // Check if the joint is mirrored already // If the joint is not mirrored, mirror jointA // Check if the joint is mirrored already // If the joint is not mirrored, mirror jointB // Add mirrored joints to array