Esempio n. 1
0
 public BayesianClassifier(string n, List <List <float> > all_data, JointMask m = JointMask.All)
 {
     Debug.Log("creating new classifier : " + n);
     pose_name = n;
     for (int i = 0; i < all_data.Count; i++)
     {
         features.Add(new feature(all_data[i]));
     }
     mask = m;
 }
Esempio n. 2
0
    void ReadFile()
    {
        TextReader tr = new StreamReader("Assets\\bayes_data.txt");

        classifiers.Clear();

        string line = tr.ReadLine();

        while (line != null)
        {
            //need to separate each feature into a different list, each different name will be associated with different instance of classifier
            string[]             sline     = line.Split(' ');
            string               pose_name = sline[0];
            List <List <float> > data      = new List <List <float> >();
            for (int i = 1; i < sline.GetLength(0) - 1; i++)
            {
                data.Add(new List <float>());
            }

            //get mask also
            int       m    = int.Parse(sline[sline.GetLength(0) - 1]);
            JointMask mask = (JointMask)m;

            while (line != null && pose_name == sline[0])
            {
                for (int i = 1; i < sline.GetLength(0); i++)
                {
                    data[i - 1].Add(float.Parse(sline[i]));
                }

                line = tr.ReadLine();
                if (line != null)
                {
                    sline = line.Split(' ');
                }
            }

            //save current data to new classifier
            classifiers.Add(new BayesianClassifier(pose_name, data, mask));
        }

        tr.Close();
    }
Esempio n. 3
0
        public static void ApplyRelativedSkeleton(ref SkeletonV1 targetPose, Animator animator, Transform container, SkeletonV1 tpose,
                                                  JointMask mask, float deltaTime)
        {
            for (int i = 0; i < targetPose.joints.Length - 1; i++)
            {
                var j    = targetPose.joints[i];
                var bone = animator.GetBoneTransform((HumanBodyBones)j.type);
                if (bone == null)
                {
                    //Debug.LogFormat("Model {0} doesn't have bone {1}", animator.gameObject.name, (HumanBodyBones)j.type);
                    continue;
                }

                /*
                 * SKIP If TPoseRot doesn't contain the joint
                 * Means we don't have startup data for that bone
                 * We'll get incorrect rotation anyway
                 */
                if (tpose.HasJoint(j.type) == false)
                {
                    continue;
                }

                var def = tpose.GetJoint(j.type);

                /*
                 * If mask out UpperBody
                 */
                if (mask.HasFlag(JointMask.UpperBody) == false)
                {
                    if (Chiron.Skeleton.Utility.IsUpperBody((HumanBodyBones)j.type))
                    {
                        continue;
                    }
                }

                /*
                 * If mask out LowerBody
                 */
                if (mask.HasFlag(JointMask.LowerBody) == false)
                {
                    if (Chiron.Skeleton.Utility.IsLowerBody((HumanBodyBones)j.type))
                    {
                        continue;
                    }
                }

                /*
                 * If mask out Hip
                 */
                if (mask.HasFlag(JointMask.Hip) == false)
                {
                    if (Chiron.Skeleton.Utility.IsHip((HumanBodyBones)j.type))
                    {
                        continue;
                    }
                }

                var t   = animator.transform;
                var rlt = t ? Quaternion.Inverse(t.rotation) * j.rot :
                          j.rot;
                var rot = rlt * def.rot;
                //rot.x *= flip.x;
                //rot.y *= flip.y;
                //rot.z *= flip.z;
                //rot.w *= flip.w;

                var pos = j.pos + def.pos;
                //bone.rotation = Quaternion.Lerp(bone.rotation, rot, normalize);
                bone.rotation = Quaternion.Lerp(bone.rotation, rot, deltaTime);

                var posDiff = pos - bone.localPosition;
                bone.localPosition = Vector3.Lerp(bone.localPosition, pos, deltaTime);

                //Guessing root transform
                var ch = container;
                ch.localPosition = Vector3.Lerp(ch.localPosition, targetPose.centerOffset, deltaTime);
            }
        }
		public BayesianClassifier(string n, List<List<float>> all_data, JointMask m = JointMask.All){
			Debug.Log("creating new classifier : " + n);
			pose_name =  n;
			for(int i = 0; i < all_data.Count; i++){
				features.Add(new feature(all_data[i]));
			}
			mask = m;
		}
		//keep track of joint mask within here
		//JOINT MASK
	/*
	 * public enum BoneMask
	{
		None = 0x0,
		Hip_Center = 0x1,
		Spine = 0x2,
		Shoulder_Center = 0x4,
		Head = 0x8,
		Shoulder_Left = 0x10,
		Elbow_Left = 0x20,
		Wrist_Left = 0x40,
		Hand_Left = 0x80,
		Shoulder_Right = 0x100,
		Elbow_Right = 0x200,
		Wrist_Right = 0x400,
		Hand_Right = 0x800,
		Hip_Left = 0x1000,
		Knee_Left = 0x2000,
		Ankle_Left = 0x4000,
		Foot_Left = 0x8000,
		Hip_Right = 0x10000,
		Knee_Right = 0x20000,
		Ankle_Right = 0x40000,
		Foot_Right = 0x80000,
		All = 0xFFFFF,
		Torso = 0x10000F, //the leading bit is used to force the ordering in the editor
		Left_Arm = 0x1000F0,
		Right_Arm = 0x100F00,
		Left_Leg = 0x10F000,
		Right_Leg = 0x1F0000,
		R_Arm_Chest = Right_Arm | Spine,
		No_Feet = All & ~(Foot_Left | Foot_Right)
	} */
		
		void SetMask(JointMask m){
			mask = m;
		}
Esempio n. 6
0
        //keep track of joint mask within here
        //JOINT MASK

        /*
         * public enum BoneMask
         * {
         *      None = 0x0,
         *      Hip_Center = 0x1,
         *      Spine = 0x2,
         *      Shoulder_Center = 0x4,
         *      Head = 0x8,
         *      Shoulder_Left = 0x10,
         *      Elbow_Left = 0x20,
         *      Wrist_Left = 0x40,
         *      Hand_Left = 0x80,
         *      Shoulder_Right = 0x100,
         *      Elbow_Right = 0x200,
         *      Wrist_Right = 0x400,
         *      Hand_Right = 0x800,
         *      Hip_Left = 0x1000,
         *      Knee_Left = 0x2000,
         *      Ankle_Left = 0x4000,
         *      Foot_Left = 0x8000,
         *      Hip_Right = 0x10000,
         *      Knee_Right = 0x20000,
         *      Ankle_Right = 0x40000,
         *      Foot_Right = 0x80000,
         *      All = 0xFFFFF,
         *      Torso = 0x10000F, //the leading bit is used to force the ordering in the editor
         *      Left_Arm = 0x1000F0,
         *      Right_Arm = 0x100F00,
         *      Left_Leg = 0x10F000,
         *      Right_Leg = 0x1F0000,
         *      R_Arm_Chest = Right_Arm | Spine,
         *      No_Feet = All & ~(Foot_Left | Foot_Right)
         * } */

        void SetMask(JointMask m)
        {
            mask = m;
        }