예제 #1
0
        /// <summary>
        /// 判断指定骨骼数据是否与指定姿势匹配
        /// </summary>
        /// <param name="skeleton">骨骼数据</param>
        /// <param name="posture">姿势</param>
        /// <returns></returns>
        public static bool matches(Skeleton skeleton, Posture posture)
        {
            PostureType postureType = posture.Type;
            Posture     pos         = computePosture(skeleton, postureType);

            return(matches(pos, posture));
        }
예제 #2
0
        /// <summary>
        /// 计算指定骨骼在指定姿势类型下,对应的姿势
        /// </summary>
        /// <param name="skeleton">骨骼数据</param>
        /// <param name="postureType">姿势类型(左臂、右臂、双臂)</param>
        /// <returns></returns>
        public static Posture computePosture(Skeleton skeleton, PostureType postureType)
        {
            Posture posture = new Posture(postureType);

            List <VectorType> vectorTypeList = getVectorTypeList(postureType);

            foreach (VectorType vectorType in vectorTypeList)
            {
                JointType jointType0, jointType1;
                switch (vectorType)
                {
                case VectorType.ShoulderElbowLeft:
                    jointType0 = JointType.ShoulderLeft;
                    jointType1 = JointType.ElbowLeft;
                    break;

                case VectorType.ElbowWristLeft:
                    jointType0 = JointType.ElbowLeft;
                    jointType1 = JointType.WristLeft;
                    break;

                case VectorType.ShoulderElbowRight:
                    jointType0 = JointType.ShoulderRight;
                    jointType1 = JointType.ElbowRight;
                    break;

                case VectorType.ElbowWristRight:
                    jointType0 = JointType.ElbowRight;
                    jointType1 = JointType.WristRight;
                    break;

                default:
                    throw new Exception("vectorType is illegal.");
                }

                Joint joint0 = skeleton.Joints[jointType0];
                Joint joint1 = skeleton.Joints[jointType1];

                Vector vector = new Vector(joint1.Position.X - joint0.Position.X, joint1.Position.Y - joint0.Position.Y, joint1.Position.Z - joint0.Position.Z);
                posture.setVector(vectorType, vector);
            }

            return(posture);
        }
예제 #3
0
        public static bool matches(Posture pos1, Posture pos2)
        {
            if (pos1.Type != pos2.Type)
            {
                return(false);
            }

            List <VectorType> vectorTypeList = getVectorTypeList(pos1.Type);

            foreach (VectorType index in vectorTypeList)
            {
                double cosineSimilarity = computeCosineSimilarity(pos1.getVector(index), pos2.getVector(index));
                if (cosineSimilarity < THRESHOLD)
                {
                    return(false);
                }
            }

            return(true);
        }