- Home /
 
Problems with VisualGestureBuilderFrameSource when adding a gesture
Hi Everyone,
I am working on a project where i have to detect custom gestures from a gesture database made with the Visual Gesture Builder.The code is the following :
 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 using Windows.Kinect;
 using Microsoft.Kinect.VisualGestureBuilder;
 using System.Linq;
 
 public class GestureManager : MonoBehaviour
 {
     Gesture walkInPlace;
     public string databaseName = "OVRGestures.gbd";
     public BodySourceManager bodyManager;
     VisualGestureBuilderDatabase db;
     VisualGestureBuilderFrameSource gestureSource;
     VisualGestureBuilderFrameReader gestureReader;
     KinectSensor sensor= null;
 
     void Start()
     {
         sensor = KinectSensor.GetDefault();
         if (sensor != null)
         {
             
             if (!sensor.IsOpen)
             {
                 Debug.Log("is OPEN");
                 sensor.Open();
             }
         }
         gestureSource = VisualGestureBuilderFrameSource.Create(sensor, 0);
         gestureReader = gestureSource.OpenReader();
         if (gestureReader != null)
         {
             gestureReader.IsPaused = true;
             gestureReader.FrameArrived += GestureFrameArrived;
             Debug.Log("IS PAUSED");
         }
         bodyManager = this.gameObject.GetComponent<BodySourceManager>();
         string path = System.IO.Path.Combine(Application.streamingAssetsPath,databaseName);
         db = VisualGestureBuilderDatabase.Create(path);
         Debug.Log("1");
         walkInPlace = db.AvailableGestures[0];
         Debug.Log("2");
         
         
         gestureSource.AddGesture(walkInPlace);
         Debug.Log("3");
 
     }
 
     // Update Loop, set body if we need one
     void Update()
     {
         if (!gestureSource.IsTrackingIdValid)
         {
             FindValidBody();
         }
     }
     // Check Body Manager, grab first valid body
     void FindValidBody()
     {
 
         if (bodyManager != null)
         {
             Body[] bodies = bodyManager.GetData();
             if (bodies != null)
             {
                 foreach (Body body in bodies)
                 {
                     if (body.IsTracked)
                     {
                         SetBody(body.TrackingId);
                         break;
                     }
                 }
             }
         }
 
     }
 
     // Public setter for Body ID to track
     public void SetBody(ulong id)
     {
         if (id > 0)
         {
             gestureSource.TrackingId = id;
             gestureReader.IsPaused = false;
         }
         else
         {
             gestureSource.TrackingId = 0;
             gestureReader.IsPaused = true;
         }
     }
 
     void GestureFrameArrived(object sender, VisualGestureBuilderFrameArrivedEventArgs e)
     {
         using (var frame = e.FrameReference.AcquireFrame())
         {
             if (frame != null)
             {
                 var discreteResults = frame.DiscreteGestureResults;
                 Debug.Log("FRAME ARRIVED");
 
                 if ((discreteResults != null) &&
                   (discreteResults.ContainsKey(this.walkInPlace)))
                 {
                     var result = discreteResults[this.walkInPlace];
                     if (result.Detected == true)
                     {
                         Debug.Log("working");
                     }
 
 
                 }
             }
 
         }
     }
 
     
 }
 
               The line that creates problems is this one:
 gestureSource.AddGesture(walkInPlace);
 
               after that unity crashes miserably without even showing an error.
I tried to fix it in several kind of ways. One of those is to replace that line with:
 Gesture[] gestures = db.AvailableGestures.ToArray<Gesture>();
 gestureSource.AddGestures(gestures);
 
               With the method AddGestures it doesn't crash but give me this erro on the unity console:
 ArgumentException: Value does not fall within the expected range.
 Rethrow as ArgumentException: This API has returned an exception from an HRESULT: 0x80070057
 Helper.ExceptionHelper.CheckLastError () (at Assets/Standard Assets/ExceptionHelper.cs:39)
 Microsoft.Kinect.VisualGestureBuilder.VisualGestureBuilderFrameSource.AddGestures (Microsoft.Kinect.VisualGestureBuilder.Gesture[] gestures) (at Assets/Standard Assets/Microsoft/Kinect/VisualGestureBuilder/VisualGestureBuilderFrameSource.cs:351)
 GestureManager.Start () (at Assets/KinectView/Scripts/GestureManager.cs:46)
 
 
               If someone knows a way to fix this I would be very thankful.
Thank you in advance
Answer by Bshow · Nov 27, 2015 at 03:16 PM
The problem solved itself.
I deleted the old progect and started a new one reimporting all the unity assets. I imported the Kinect.VisualGestureBuilder asset before the Kinect asset.
Answer by sebtoun · May 25, 2016 at 09:53 AM
I fixed the problem of having the exception thrown (ArgumentException: Value does not fall within the expected range.) when AddGestures was called by not calling property accessor AvailableGestures more than one time. I instead cached the result and reused it. It may be related with Helper.NativeObjectCache I did not investigate more than that.
That solved it for me, thanks
Was doing
 foreach (var gesture in gestureDatabase.AvailableGestures)
 
                  Changed it to
 var gestures = gestureDatabase.AvailableGestures;
 foreach (var gesture in gestures)
                 Your answer
 
             Follow this Question
Related Questions
Shooting with get joint rotation .eulerAngles kinect 0 Answers
Strange Files Replacing My Game Files? 1 Answer
Is it possible to load a VideoClip at runtime from streaming assets 0 Answers
Unity 5.4.0f3 (64-bit) Crahed on startup! 2 Answers
Rigidbody and forces not working after unity crashed 1 Answer