/// <summary> /// Sets the current depth camera mode /// </summary> /// <param name="mode"> /// Depth camera mode to switch to. /// </param> protected void SetDepthMode(DepthFrameMode mode) { // Is this a different mode? if (this.Mode == mode) { return; } // Stop camera first if running bool running = this.IsRunning; if (running) { this.Stop(); } // Check to make sure mode is valid by finding it again DepthFrameMode foundMode = DepthFrameMode.Find(mode.Format, mode.Resolution); if (foundMode == null) { throw new Exception("Invalid Depth Camera Mode: [" + mode.Format + ", " + mode.Resolution + "]"); } // Save mode this.captureMode = mode; // All good, switch to new mode int result = KinectNative.freenect_set_depth_mode(this.parentDevice.devicePointer, foundMode.nativeMode); if (result != 0) { throw new Exception("Mode switch failed. Error Code: " + result); } // Update depth map this.UpdateNextFrameDepthMap(); // If we were running before, start up again if (running) { this.Start(); } }