none
Visual Gesture Builder - DiscreteGestureResult Problem RRS feed

  • Question

  • I have used the provided samples to attempt to write my own applications that used Visual Gesture Builder. I know my database works correctly as I was able to input the data into the seated example and it worked without a problem. Using break points I have managed to narrow the problem down to the following code.

    The exception that is thrown is that DiscreteGestureResults is null.

    Any ideas?

            public void GestureFrameArrived(object sender, VisualGestureBuilderFrameArrivedEventArgs args)
            {
                VisualGestureBuilderFrameReference frameReference = args.FrameReference;
                using (VisualGestureBuilderFrame frame = frameReference.AcquireFrame())
                {
                    if (frame != null)
                    {
                        var resultBT = frame.DiscreteGestureResults[BottomToTop];
                        var resultTB = frame.DiscreteGestureResults[TopToBottom];
                        var resultRL = frame.DiscreteGestureResults[RightToLeft];
                        var resultLR = frame.DiscreteGestureResults[LeftToRight];
                        var resultIO = frame.DiscreteGestureResults[InToOut];
                        var resultOI = frame.DiscreteGestureResults[OutToIn];
    
                        if (resultBT.Detected == true)
                        {
                            if (resultBT.Confidence > 0.35)
                            {
                                GestureOut.Text = resultBT.Detected ? "BottomToTop" : "None";
                                //ConfidenceText.Text = resultBT.Confidence.ToString();
                            }
                        }


    Wednesday, December 10, 2014 10:05 PM

All replies

  • On a frame, not every gesture would be detected. Are all 6 of the gestures you have listed null, or only the BT result null for the time it fails?

    Carmine Sirignano - MSFT

    Thursday, December 11, 2014 8:04 PM
  • They are all null.

    I recreate the code in full in a simplied form so it is only looking for one gesture in my database called TopToBottom. It might be something I have written elsewhere that is incorrect.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using Microsoft.Kinect;
    using Microsoft.Kinect.VisualGestureBuilder;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            Gesture TopToBottomGesture = null;
            KinectSensor kinect;
            Body[] bodies;
            BodyFrameReader bodyreader;
            VisualGestureBuilderFrameSource vgbFrameSource;
            VisualGestureBuilderFrameReader vgbFrameReader;
    
            public Form1()
            {
                kinect = KinectSensor.GetDefault();
                kinect.Open();
    
                InitializeComponent();
    
                if (bodies == null)
                {
                    bodies = new Body[kinect.BodyFrameSource.BodyCount];
                }
                bodyreader = kinect.BodyFrameSource.OpenReader();
                bodyreader.FrameArrived += OnBodyFrameArrived;
                
                VisualGestureBuilderDatabase database = new VisualGestureBuilderDatabase(@"Database\Robot.gbd");
                vgbFrameSource = new VisualGestureBuilderFrameSource(kinect, 0);
                foreach (var gesture in database.AvailableGestures)
                {
                    if (gesture.Name == "TopToBottom")
                    {
                        TopToBottomGesture = gesture;
                        txtDebug.Text = "Gesture Added";
                    }
                }
    
                vgbFrameSource.TrackingIdLost += OnTrackingIdLost;
    
                vgbFrameReader = this.vgbFrameSource.OpenReader();
                vgbFrameReader.IsPaused = true;
                vgbFrameReader.FrameArrived += OnGestureFrameArrived;
     
            }
    
            private void cmdClose_Click(object sender, EventArgs e)
            {
                if(vgbFrameReader != null)
                {
                    vgbFrameReader.FrameArrived -= OnGestureFrameArrived;
                    vgbFrameReader.Dispose();
                    vgbFrameReader = null;
                }
    
                if (vgbFrameSource != null)
                {
                    vgbFrameSource.TrackingIdLost -= OnTrackingIdLost;
                    vgbFrameSource.Dispose();
                }
    
                bodyreader.Dispose();
                bodyreader = null;
    
                kinect.Close();
                kinect = null;
            }
    
            void OnBodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
            {
                using (var frame = e.FrameReference.AcquireFrame())
                {
                    if (frame != null)
                    {
                        frame.GetAndRefreshBodyData(bodies);
                        var trackedBody = bodies.Where(b => b.IsTracked).FirstOrDefault();
    
                        if (trackedBody != null)
                        {
                            if(vgbFrameReader.IsPaused)
                            {
                                vgbFrameSource.TrackingId = trackedBody.TrackingId;
                                vgbFrameReader.IsPaused = false;
                                txtKinectTrack.Text = "Body Tracked";
                            }
                        }
                        else
                            OnTrackingIdLost(null, null);
                    }
                }
            }
    
            void OnGestureFrameArrived(object sender, VisualGestureBuilderFrameArrivedEventArgs e)
            {
                VisualGestureBuilderFrameReference frameReference = e.FrameReference;
                using (VisualGestureBuilderFrame frame = frameReference.AcquireFrame())
                {
                    if (frame != null)
                    {
                        var discreteResults = frame.DiscreteGestureResults;
                        txtDebug.Text = "Frame";
                        
                        if (discreteResults != null) 
                        {
                            var result = discreteResults[TopToBottomGesture];
    
                            txtDebug.Text = "Discrete Gesture Results";
    
                            if(result.Detected == true)
                            {
                                txtGestureOutput.Text = "Captured";
                                txtConfidence.Text = result.Confidence.ToString();
                            }
                            else
                            {
                                txtGestureOutput.Text = "No Gesture Detected";
                                txtConfidence.Text = "0";
                            }
                        }
                    }
                }
            }
    
            void OnTrackingIdLost(object sender, TrackingIdLostEventArgs e)
            {
                vgbFrameReader.IsPaused = true;
                txtKinectTrack.Text = "ID Lost";
            }
        }
    }
    


    Saturday, December 13, 2014 3:05 PM
  • Looks like you may introduce a bug since you are making an assumption in your tracking strategy. While this is fine for single user scenario, the assumption the first tracked body is always the same is incorrect. How do you account for "ghost" of single frame result of the body. You may want to follow the tracking strategy defined from the sample(GestureDetector.cs - this.IsTracked)


    Carmine Sirignano - MSFT

    Monday, December 15, 2014 7:40 PM