/// <summary> /// Start tracking hands with all key poses disabled. /// </summary> /// <returns> /// MLResult.Result will be <c>MLResult.Code.Ok</c> if successful. /// MLResult.Result will be <c>MLResult.Code.UnspecifiedFailure</c> if failed to initialize the native hand tracker. /// </returns> protected override MLResult.Code StartAPI() { this.left = new Hand(MLHandTracking.HandType.Left); this.right = new Hand(MLHandTracking.HandType.Right); // Initialize KeyPoseManager, to register the gesture subsystem. this.keyposeManager = new KeyposeManager(Left, Right); try { // Attempt to start the tracker & validate. NativeBindings.SetHandGesturesEnabled(true); if (!NativeBindings.IsHandGesturesEnabled()) { MLPluginLog.Error("MLHandTracking.StartAPI failed to initialize the native hand tracker."); return(MLResult.Code.UnspecifiedFailure); } } catch (EntryPointNotFoundException) { MLPluginLog.Error("MLHandTracking.StartAPI failed. Reason: API symbols not found."); return(MLResult.Code.UnspecifiedFailure); } return(MLResult.Code.Ok); }
/// <summary> /// Cleans up API and unmanaged memory. /// </summary> protected override MLResult.Code StopAPI() { // The KeyPoseManager object will not receive any more updates from Left or Right hands. this.keyposeManager.Dispose(); this.keyposeManager = null; this.left = null; this.right = null; NativeBindings.SetHandGesturesEnabled(false); return(MLResult.Code.Ok); }
/// <summary> /// Cleans up API and unmanaged memory. /// </summary> /// <param name="isSafeToAccessManagedObjects">Allow complete cleanup of the API.</param> protected override void CleanupAPI(bool isSafeToAccessManagedObjects) { if (isSafeToAccessManagedObjects) { // The KeyPoseManager object will not receive any more updates from Left or Right hands. this.keyposeManager = null; this.left = null; this.right = null; } try { // Attempt to stop the tracker. NativeBindings.SetHandGesturesEnabled(false); } catch (EntryPointNotFoundException) { MLPluginLog.Error("MLHandTracking.CleanupAPI failed. Reason: API symbols not found"); } }