public float DistanceTo(DGInstanceSample otherInstance)
        {
            float dgDistance = 0;

            //distance += (this as SGClass).DistanceTo(otherInstance);

            // Need to figure out how to weight these DG features appropriately.
            int dgFeatureCount = 0;

            if (otherInstance.LeftHand != null)
            {
                dgDistance += MeanLeftPalmVelocity.DistanceTo(otherInstance.LeftPalmVelocity) / StdDevLeftPalmVelocity;
                dgFeatureCount++;
            }
            if (otherInstance.RightHand != null)
            {
                dgDistance += MeanRightPalmVelocity.DistanceTo(otherInstance.RightPalmVelocity) / StdDevRightPalmVelocity;
                dgFeatureCount++;
            }

            dgDistance /= (float)dgFeatureCount;
            float sgDistance = base.DistanceTo(otherInstance as SGInstance);

            // The two weights must add up to 1.0f
            float sgWeight = 0.5f;
            float dgWeight = 0.5f;

            float result = (dgDistance * dgWeight) + (sgDistance * sgWeight);

            return(result);
        }
        //TODO: Check if this works (with all the casting and stuff).
        public DGInstanceSample Lerp(DGInstanceSample otherInstance, float amount)
        {
            SGInstance sgLerp       = base.Lerp(otherInstance, amount);
            var        lerpedSample = new DGInstanceSample(sgLerp);

            if (LeftHand != null)
            {
                lerpedSample.LeftPalmVelocity = LeftPalmVelocity.Lerp(otherInstance.LeftPalmVelocity, amount);
            }
            if (RightHand != null)
            {
                lerpedSample.RightPalmVelocity = RightPalmVelocity.Lerp(otherInstance.RightPalmVelocity, amount);
            }
            return(lerpedSample);
        }
Пример #3
0
        public void ProcessFrame(Frame frame)
        {
            if (_lastFrame == null)
            {
                _lastFrame = frame;
                return;
            }

            bool handsStill = handsAreStill(frame);

            if (frame.Hands.Count == 0)
            {
                State = DGRecorderState.WaitingForHands;
            }

            switch (State)
            {
            case DGRecorderState.WaitingForHands:
                if (frame.Hands.Count > 0)
                {
                    _stillGesture = new SGInstance(frame);
                    State         = DGRecorderState.WaitingToStart;
                }
                break;

            case DGRecorderState.WaitingToStart:
                if (handsStill)
                {
                    _startOfGesture = new DGInstanceSample(frame);
                    _gestureSamples = new List <DGInstanceSample>();
                    _gestureSamples.Add(_startOfGesture);

                    State = DGRecorderState.InStartPosition;
                }
                break;

            case DGRecorderState.InStartPosition:
                if (!handsStill)
                {
                    State = DGRecorderState.RecordingGesture;
                }
                break;

            case DGRecorderState.RecordingGesture:
                if (handsStill)
                {
                    // Trim the extra samples in back (from holding hand still for X seconds)
                    int stillFrames = (int)(_frameRate * _stillSeconds);
                    _gestureSamples.RemoveRange(_gestureSamples.Count - stillFrames, stillFrames);

                    MostRecentInstance = new DGInstance(_gestureSamples);
                    if (_inRecordMode)
                    {
                        Instances.Add(MostRecentInstance);
                    }

                    State = DGRecorderState.RecordingJustFinished;                             // Put this first so "InEndPosition" is printed while we process the frames
                }
                else
                {
                    _gestureSamples.Add(new DGInstanceSample(frame));
                }
                break;

            case DGRecorderState.RecordingJustFinished:
                State = DGRecorderState.InEndPosition;
                break;

            case DGRecorderState.InEndPosition:
                if (!handsStill)
                {
                    State = DGRecorderState.WaitingToStart;
                }
                break;
            }
        }