Skip to content

Commit

Permalink
infer skeleton direction for 2D skeleton
Browse files Browse the repository at this point in the history
With this, the skeleton player on the record page turns around whenever
the dancer does. In 90° steps, but that's the 2.1D I'm going for now.
  • Loading branch information
jakmeier committed Dec 18, 2023
1 parent 6582b79 commit d414847
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 20 deletions.
7 changes: 5 additions & 2 deletions bouncy_instructor/src/intern/skeleton_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,11 @@ impl Skeleton3d {
self.direction
}

pub(crate) fn to_skeleton(&self, rotation: f32, sideway: bool) -> Skeleton {
// TODO: add an option to NOT undo the normalization azimuth rotation
pub(crate) fn to_skeleton(&self, rotation: f32) -> Skeleton {
let sideway = match self.direction() {
Direction::North | Direction::South | Direction::Unknown => false,
Direction::East | Direction::West => true,
};
let correction = self.azimuth_correction - SignedAngle::degree(rotation);
let segment = |i: LimbIndex| -> Segment {
Angle3d::new(
Expand Down
1 change: 1 addition & 0 deletions bouncy_instructor/src/intern/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ mod detection;
pub(crate) struct Step {
pub name: String,
pub poses: Vec<usize>,
#[allow(dead_code)]
pub directions: Vec<Direction>,
}
10 changes: 3 additions & 7 deletions bouncy_instructor/src/public/skeleton.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::intern::geom::Angle3d;
use crate::intern::pose::Pose;
use crate::intern::pose_db::LimbPositionDatabase;
use crate::intern::skeleton_3d::{Direction, Skeleton3d};
use crate::intern::skeleton_3d::Skeleton3d;
use std::f32::consts::TAU;
use wasm_bindgen::prelude::wasm_bindgen;

Expand Down Expand Up @@ -50,13 +50,9 @@ pub struct Segment {
}

impl Skeleton {
pub(crate) fn from_pose(pose: &Pose, direction: Direction, db: &LimbPositionDatabase) -> Self {
pub(crate) fn from_pose(pose: &Pose, db: &LimbPositionDatabase) -> Self {
let rotation = 0.0;
let sideway = match direction {
Direction::North | Direction::South | Direction::Unknown => false,
Direction::East | Direction::West => true,
};
Skeleton3d::from_with_db(pose, db).to_skeleton(rotation, sideway)
Skeleton3d::from_with_db(pose, db).to_skeleton(rotation)
}
}

Expand Down
5 changes: 2 additions & 3 deletions bouncy_instructor/src/public/step_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ impl From<&Step> for StepInfo {
let skeletons = STATE.with_borrow(|state| {
step.poses
.iter()
.enumerate()
.map(|(i, pose_index)| {
.map(|pose_index| {
let pose = &state.db.poses()[*pose_index];
Skeleton::from_pose(pose, step.directions[i], &state.db)
Skeleton::from_pose(pose, &state.db)
})
.collect()
});
Expand Down
11 changes: 3 additions & 8 deletions bouncy_instructor/src/public/tracker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ impl Tracker {
self.timestamps.push(timestamp);
self.keypoints.push(keypoints);
let skeleton_info = Skeleton3d::from_keypoints(&keypoints);
let front = skeleton_info.to_skeleton(0.0, false);
let side = skeleton_info.to_skeleton(90.0, true);
let front = skeleton_info.to_skeleton(0.0);
let side = skeleton_info.to_skeleton(90.0);
self.skeletons.push(skeleton_info);
Skeletons { front, side }
}
Expand Down Expand Up @@ -121,12 +121,7 @@ impl Tracker {
pub fn skeleton_at(&self, timestamp: Timestamp) -> Option<Skeleton> {
let i = self.timestamps.partition_point(|t| *t < timestamp);
if let Some(skeleton_info) = &self.skeletons.get(i) {
let direction = skeleton_info.direction();
use crate::intern::skeleton_3d::Direction;
Some(
skeleton_info
.to_skeleton(0.0, matches!(direction, Direction::East | Direction::West)),
)
Some(skeleton_info.to_skeleton(0.0))
} else {
None
}
Expand Down

0 comments on commit d414847

Please sign in to comment.