Esempio n. 1
0
        void gestureFrameReaders_FrameArrived(object sender, VisualGestureBuilderFrameArrivedEventArgs e)
        {
            VisualGestureBuilderFrame gestureFrame = e.FrameReference.AcquireFrame();

            if (gestureFrame == null)
            {
                return;
            }
            UpdateGestureFrame(gestureFrame);
            gestureFrame.Dispose();
        }
    private bool UpdateVisualGestures(long userId)
    {
        if (vgbFrameSource == null || vgbFrameReader == null)
        {
            return(false);
        }

        bool wasPaused = vgbFrameReader.IsPaused;

        vgbFrameSource.TrackingId = (ulong)userId;
        vgbFrameReader.IsPaused   = (userId == 0);

        if (vgbFrameReader.IsPaused)
        {
            if (!wasPaused)
            {
                // clear the gesture states
                foreach (Gesture gesture in vgbFrameSource.Gestures)
                {
                    if (gestureData.ContainsKey(gesture.Name))
                    {
                        VisualGestureData data = gestureData[gesture.Name];

                        data.userId     = 0;
                        data.isComplete = false;
                        //data.isResetting = false;
                        data.isProcessed = false;
                        data.confidence  = 0f;
                        data.progress    = 0f;
                        data.timestamp   = Time.realtimeSinceStartup;

                        gestureData[gesture.Name] = data;
                    }
                }
            }

            return(false);
        }

        VisualGestureBuilderFrame frame = vgbFrameReader.CalculateAndAcquireLatestFrame();

        if (frame != null)
        {
            Dictionary <Gesture, DiscreteGestureResult>   discreteResults   = frame.DiscreteGestureResults;
            Dictionary <Gesture, ContinuousGestureResult> continuousResults = frame.ContinuousGestureResults;

            if (discreteResults != null)
            {
                foreach (Gesture gesture in discreteResults.Keys)
                {
                    if (gesture.GestureType == GestureType.Discrete && gestureData.ContainsKey(gesture.Name))
                    {
                        DiscreteGestureResult result = discreteResults[gesture];
                        VisualGestureData     data   = gestureData[gesture.Name];

                        data.userId     = vgbFrameSource.IsTrackingIdValid ? (long)vgbFrameSource.TrackingId : 0;
                        data.isComplete = result.Detected;
                        data.confidence = result.Confidence;
                        data.timestamp  = Time.realtimeSinceStartup;

                        //Debug.Log(string.Format ("{0} - {1}, confidence: {2:F0}%", data.gestureName, data.isComplete ? "Yes" : "No", data.confidence * 100f));

                        if (data.isProcessed && !data.isComplete)
                        {
                            //data.isResetting = false;
                            data.isProcessed = false;
                        }

                        gestureData[gesture.Name] = data;
                    }
                }
            }

            if (continuousResults != null)
            {
                foreach (Gesture gesture in continuousResults.Keys)
                {
                    if (gesture.GestureType == GestureType.Continuous && gestureData.ContainsKey(gesture.Name))
                    {
                        ContinuousGestureResult result = continuousResults[gesture];
                        VisualGestureData       data   = gestureData[gesture.Name];

                        data.userId = vgbFrameSource.IsTrackingIdValid ? (long)vgbFrameSource.TrackingId : 0;
                        float prevProgress = data.progress;
                        data.progress  = result.Progress;
                        data.timestamp = Time.realtimeSinceStartup;

                        if (data.isProcessed && data.progress >= minConfidence && data.progress != prevProgress)
                        {
                            //data.isResetting = false;
                            data.isProcessed = false;
                        }

                        gestureData[gesture.Name] = data;
                    }
                }
            }

            frame.Dispose();
            frame = null;
        }

        return(true);
    }