1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use serde::{Deserialize, Serialize};
use std::fmt::Debug;
use wasm_bindgen::JsValue;

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Keypoint {
    pub x: f64,
    pub y: f64,
    pub z: Option<f64>,
    pub score: Option<f64>,
    pub name: Option<String>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct BoundingBox {
    pub x_min: f64,
    pub y_min: f64,
    pub x_max: f64,
    pub y_max: f64,
    pub width: f64,
    pub height: f64,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Pose {
    pub keypoints: Vec<Keypoint>,
    pub score: Option<f64>,
    pub keypoints_3d: Option<Vec<Keypoint>>,
    pub bounding_box: Option<BoundingBox>,
    // TODO: segmentation
    pub id: Option<f64>,
}

impl TryFrom<JsValue> for Pose {
    fn try_from(value: JsValue) -> Result<Self, Self::Error> {
        Ok(serde_wasm_bindgen::from_value::<Self>(value)?)
    }

    type Error = serde_wasm_bindgen::Error;
}