protected override bool Recognise(FeatureData data)
 {
     switch (_motionState)
     {
         case MotionState.Initial:
             float footHeight = data.CalculateDifferY(JointType.AnkleRight, JointType.AnkleLeft);
             // 判断是否抬高脚data.CompareThresholdY(JointType.AnkleRight, JointType.AnkleLeft, 15) == 1
             if (footHeight > MinFootHeight &&
                 footHeight < MaxFootHeight) // 用Y判断脚抬高度,脚离地阈值为15
             {
                 _motionState = MotionState.Invalid;// 标记为无效,等待放下脚恢复初始状态
                 if (data.CompareThresholdZ(JointType.AnkleRight, JointType.HipRight, 30) == 0 && // 用Z排除非前踢腿
                 data.CompareThresholdX(JointType.AnkleRight, JointType.HipRight, 15) == 0) // 用X排除非左右侧踢腿
                 {
                     return true;
                 }
             }
             break;
         default:
             // 放下脚恢复初始状态
             if (data.CompareThresholdY(JointType.AnkleRight, JointType.AnkleLeft, 5) == 0)
             {
                 _motionState = MotionState.Initial;
             }
             break;
     }
     return false;
 }
Beispiel #2
0
        private const float LegRadianThreshold = 0.57f; //30, 0.64f; //弧度阈值;40度约为0.64左右,45度约为0.707

        #endregion Fields

        #region Methods

        protected override bool Recognise(FeatureData data)
        {
            switch (_motionState)
            {
                case MotionState.Initial:
                    // 判断是否抬高脚
                    if (data.CompareThresholdY(JointType.AnkleRight, JointType.AnkleLeft, 10) == 1) // 用Y判断脚抬高度,脚离地阈值为10
                    {
                        _motionState = MotionState.Valid;
                    }
                    break;
                case MotionState.Valid:
                    // 区别抬脚动作
                    if (data.CompareThresholdZ(JointType.AnkleRight, JointType.HipRight, 30) == 0 &&
                        data.CompareThresholdX(JointType.AnkleRight, JointType.HipRight, 15) == 0)
                    {
                        _motionState = MotionState.Invalid;
                        return false;
                    }
                    // 大概的腿长,从踝开始计算
                    float legLength = data.CalculateDifferY(JointType.HipLeft, JointType.AnkleLeft);
                    if (legLength <= 0) // 腿长不适合理论数据
                    {
                        return false;
                    }
                    // 在x和z轴上的映射投影距离差值
                    float ankleDifferX = Math.Abs(data.CalculateDifferX(JointType.AnkleRight, JointType.AnkleLeft));
                    float ankleDifferZ = Math.Abs(data.CalculateDifferZ(JointType.AnkleRight, JointType.AnkleLeft));

                    if (ankleDifferX >= ankleDifferZ) // 排除向前或后踢的情况
                    {
                        // 计算腿抬起后裸相差的水平距离
                        float ankleHorizontalDistance = (float)Math.Sqrt(ankleDifferX * ankleDifferX + ankleDifferZ * ankleDifferZ);

                        // 计算腿抬起的弧度
                        float legRadian = ankleHorizontalDistance / legLength;

                        // 当抬起角度超过弧度阈值后生效
                        if (legRadian > LegRadianThreshold)
                        {
                            _motionState = MotionState.Invalid;
                            return true;
                        }
                    }
                    else
                    {
                        _motionState = MotionState.Invalid;
                    }
                    break;
                default:
                    // 放下脚恢复初始状态
                    if (data.CompareThresholdY(JointType.AnkleRight, JointType.AnkleLeft, 5) == 0)
                    {
                        _motionState = MotionState.Initial;
                    }
                    break;
            }
            return false;
        }