Search code examples
c#kinectkinect-sdkgesture-recognition

Unable to use the 'Gesture Detection using Kinect' from the Kinect SDK samples


I am using Gesture Detection to detect a gesture which in turn triggers a method call to save an image. Here's the code in C# for the MainWindow which uses the classes for GestureDetect and GestureResult from the samples in the Kinect SDK. What I want to do is get the updated value for result from the GestureDetect.

public MainWindow()
    {
           kinectSensor = KinectSensor.GetDefault();
       this.kinectSensor.IsAvailableChanged += this.Sensor_IsAvailableChanged;

        Application.Current.MainWindow.WindowState = WindowState.Maximized;

         kinectSensor.Open();
         this.StatusText = this.kinectSensor.IsAvailable ? Properties.Resources.RunningStatusText
                                                        : Properties.Resources.NoSensorStatusText;
         this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader();

         this.choice = new List<bool>();
       this.bodyFrameReader.FrameArrived += this.Reader_BodyFrameArrived;
       _backgroundRemovalTool = new BackgroundRemovalTool(kinectSensor.CoordinateMapper);
       _reader = kinectSensor.OpenMultiSourceFrameReader(FrameSourceTypes.Color | FrameSourceTypes.Depth | FrameSourceTypes.BodyIndex);
       _reader.MultiSourceFrameArrived += Reader_MultiSourceFrameArrived;
       this.gestureDetectorList = new List<GestureDetect>();
        InitializeComponent();
        //GestureDetect detector = new GestureDetect(this.kinectSensor);

        // 2) Initialize the background removal tool.

        int maxBodies = this.kinectSensor.BodyFrameSource.BodyCount;
        for (int i = 0; i < maxBodies; ++i)
        {
            GestureResult result = new GestureResult(i, false, false, 0.0f);

            GestureDetect detector = new GestureDetect(this.kinectSensor, result);
            this.gestureDetectorList.Add(detector);

            this.bodyFrameReader.FrameArrived += this.Reader_BodyFrameArrived;

            choice.Add(result.detected);

        }



    }

The value of choice[i] remains false and gestureDetectorList[i].result is null for the bodies. Where am I going wrong?


Solution

  • Ok I still don't know where I was going wrong. What I did was work around this by creating methods to update flags in MainWindow from within `GestureDetect' funtion and using those flags to call my 'Capture' method.

    So that's a possible workaround. If somebody can tell me where I was going wroung though I would really appreciate it as I couldn't figure it out.

    Thanks.