Skip to content

Commit

Permalink
add bounding box mirroring (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyuan-linn authored Jul 23, 2024
1 parent 542e5a5 commit bac9e87
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/BodyPose/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ class BodyPose {
}
if (this.runtimeConfig.flipHorizontal) {
this.mirrorKeypoints(result, image.width);
this.mirrorBoundingBox(result);
}
this.addKeypoints(result);
this.resizeBoundingBoxes(result, image.width, image.height);
Expand Down Expand Up @@ -333,6 +334,7 @@ class BodyPose {
}
if (this.runtimeConfig.flipHorizontal) {
this.mirrorKeypoints(result, this.detectMedia.width);
this.mirrorBoundingBox(result);
}
this.addKeypoints(result);
this.resizeBoundingBoxes(
Expand Down Expand Up @@ -388,6 +390,20 @@ class BodyPose {
});
}

/**
* Mirror the bounding box around x-axis.
* @param {Object} poses - the original detection results.
* @private
*/
mirrorBoundingBox(poses) {
poses.forEach((pose) => {
if (!pose.box) return;
const tempXMin = pose.box.xMin;
pose.box.xMin = 1 - pose.box.xMax;
pose.box.xMax = 1 - tempXMin;
});
}

/**
* Resize the keypoints output of moveNet model to match the display size.
*
Expand Down

0 comments on commit bac9e87

Please sign in to comment.