Example #1
0
        // Converts JSON string to PoseData pose
        public static PoseData JSONstring2PoseData(string frame_json)
        {
            JointData[] joint_data_recorded_array = new JointData[(int)JointId.Count];
            PoseData    recorded_data             = new PoseData {
                data = { }
            };

            //Debug.Log(frame_json);
            PoseDataJSON saved_joint_data = JsonUtility.FromJson <PoseDataJSON>(frame_json);

            for (JointId jt = 0; jt < JointId.Count; jt++)
            {
                // play recording
                JointDataJSON jd              = saved_joint_data.data[(int)jt];
                Vector3       v_saved         = JsonUtility.FromJson <Vector3>(jd.position);
                Quaternion    r_saved         = JsonUtility.FromJson <Quaternion>(jd.rotation);
                var           joint_data_live = new JointData
                {
                    Position    = v_saved,
                    Orientation = r_saved
                };
                joint_data_recorded_array[(int)jt] = joint_data_live;
            }
            recorded_data = new PoseData {
                data = joint_data_recorded_array
            };
            return(recorded_data);
        }
Example #2
0
        // Converts Azure Kinect SDK BT Body to PoseDataJSON (serializable for JSON) pose
        public static PoseDataJSON Body2PoseDataJSON(Body body)
        {
            JointDataJSON[] joint_data_array = new JointDataJSON[(int)JointId.Count];
            for (JointId jt = 0; jt < JointId.Count; jt++)
            {
                // write recorded poses to file
                Microsoft.Azure.Kinect.BodyTracking.Joint joint = body.Skeleton.GetJoint(jt);
                var pos         = joint.Position;
                var orientation = joint.Quaternion;
                // save raw data
                var v          = new Vector3(pos.X, pos.Y, pos.Z);
                var r          = new Quaternion(orientation.X, orientation.Y, orientation.Z, orientation.W);
                var joint_data = new JointDataJSON {
                    position = JsonUtility.ToJson(v), rotation = JsonUtility.ToJson(r)
                };
                joint_data_array[(int)jt] = joint_data;
            }
            PoseDataJSON jdl = new PoseDataJSON {
                data = joint_data_array
            };

            return(jdl);
        }