public KinectCoreV2(ref KinectBase.MasterSettings settings, bool isGUILaunched, int kinectNumber) { masterSettings = settings; dynamic temp = masterSettings.kinectOptionsList[kinectNumber]; masterKinectSettings = (KinectV2Settings)temp; //TODO: Update this to open a specific Kinect v2, if the SDK is ever updated to support multiple on one machine kinect = KinectSensor.GetDefault(); kinectID = kinectNumber; uint tempC = kinect.ColorFrameSource.FrameDescription.LengthInPixels; uint tempD = kinect.DepthFrameSource.FrameDescription.LengthInPixels; uint tempI = kinect.InfraredFrameSource.FrameDescription.LengthInPixels; colorImagePool = new KinectBase.ObjectPool<byte[]>(() => new byte[tempC * 4]); depthImagePool = new KinectBase.ObjectPool<byte[]>(() => new byte[tempD * 4]); irImagePool = new KinectBase.ObjectPool<byte[]>(() => new byte[tempI * sizeof(UInt16)]); if (isGUILaunched) { isGUI = true; LaunchKinect(); } else { launchKinectDelegate kinectDelegate = LaunchKinect; IAsyncResult result = kinectDelegate.BeginInvoke(null, null); kinectDelegate.EndInvoke(result); //Even though this is blocking, the events should be on a different thread now. } }
//TODO: Subscribe this to the skeletonChanged event and update the GUI with a preview of the skeleton positions public NetworkKinectSettingsControl(int kinectNumber, ref KinectBase.MasterSettings settings, KinectBase.IKinectCore kinect) { if (settings != null) { if (settings.kinectOptionsList[kinectNumber].version == KinectBase.KinectVersion.NetworkKinect) { masterSettings = settings; dynamic tempSettings = settings.kinectOptionsList[kinectNumber]; kinectSettings = (NetworkKinectSettings)tempSettings; kinectID = kinectNumber; kinectCore = (NetworkKinectCore)kinect; uniqueKinectID = kinect.uniqueKinectID; InitializeComponent(); this.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; this.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; //Set the binding on the joint mapping data grid jointMappingDataGrid.ItemsSource = kinectSettings.jointMappings; jointMappingDataGrid.Items.Refresh(); } else { throw new ArgumentException("The provided KinectID is not for a network Kinect sensor."); } } else { throw new ArgumentNullException("settings"); } }
public KinectV2SettingsControl(int kinectNumber, ref KinectBase.MasterSettings settings, KinectBase.IKinectCore kinect) { if (settings != null) { if (settings.kinectOptionsList[kinectNumber].version == KinectBase.KinectVersion.KinectV2) { masterSettings = settings; dynamic tempSettings = settings.kinectOptionsList[kinectNumber]; kinectSettings = (KinectV2Settings)tempSettings; kinectID = kinectNumber; kinectCore = (KinectCoreV2)kinect; uniqueKinectID = kinect.uniqueKinectID; InitializeComponent(); this.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; this.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; } else { throw new ArgumentException("The provided KinectID is not for a Kinect v2 sensor."); } } else { throw new NotSupportedException("Method arguments are invalid!"); } }
//Why is the kinectNumber nullable if it is requried later? public KinectCoreV1(ref KinectBase.MasterSettings settings, bool isGUILaunched, int? kinectNumber = null) { if (kinectNumber != null) { masterSettings = settings; dynamic tempSettings = masterSettings.kinectOptionsList[(int)kinectNumber]; //We have to use dynamic because the type of the Kinect settings in the master list isn't defined until runtime masterKinectSettings = (KinectV1Settings)tempSettings; //Initialize the object pools colorImagePool = new KinectBase.ObjectPool<byte[]>(() => new byte[640 * 480 * 4]); depthImagePool = new KinectBase.ObjectPool<byte[]>(() => new byte[640 * 480 * 4]); //Note: the kinectNumber could be greater than the number of Kinect v1s if there are other types of sensors in use //Therefore, we have to find the correct Kinect, if it exists using this loop int globalIndex = -1; for (int i = 0; i < KinectSensor.KinectSensors.Count; i++) { if (KinectSensor.KinectSensors[i].DeviceConnectionId == masterSettings.kinectOptionsList[(int)kinectNumber].uniqueKinectID) { globalIndex = i; break; } } if (globalIndex >= 0) { kinect = KinectSensor.KinectSensors[globalIndex]; kinectID = (int)kinectNumber; } else { throw new System.IndexOutOfRangeException("Specified Kinect sensor does not exist"); } if (isGUILaunched) { isGUI = true; LaunchKinect(); } else { launchKinectDelegate kinectDelegate = LaunchKinect; IAsyncResult result = kinectDelegate.BeginInvoke(null, null); kinectDelegate.EndInvoke(result); //Even though this is blocking, the events should be on a different thread now. } } else { //TODO: Open the default Kinect? throw new NullReferenceException("To create a KinectCore object, the KinectNumber must be valid."); } }
public void UpdateGUI(KinectBase.MasterSettings settings) { if (kinectID.HasValue) { masterSettings = settings; dynamic tempSettings = masterSettings.kinectOptionsList[kinectID.Value]; kinectSettings = (NetworkKinectSettings)tempSettings; //Shutdown the server, if it is running bool wasRunning = false; if (kinectCore.isKinectRunning) { kinectCore.ShutdownSensor(); wasRunning = true; } //Update the skeleton server and joint mappings serverNameTextBox.Text = kinectSettings.serverName; jointMappingDataGrid.ItemsSource = kinectSettings.jointMappings; jointMappingDataGrid.Items.Refresh(); //Update the physical position xPosTextBox.Text = kinectSettings.kinectPosition.X.ToString(); yPosTextBox.Text = kinectSettings.kinectPosition.Y.ToString(); zPosTextBox.Text = kinectSettings.kinectPosition.Z.ToString(); yawTextBox.Text = kinectSettings.kinectYaw.ToString(); pitchTextBox.Text = kinectSettings.kinectPitch.ToString(); rollTextBox.Text = kinectSettings.kinectRoll.ToString(); //Update the hand grab data lhServerTextBox.Text = kinectSettings.lhServerName; lhChannelTextBox.Text = kinectSettings.lhChannel.ToString(); rhServerTextBox.Text = kinectSettings.rhServerName; rhChannelTextBox.Text = kinectSettings.rhChannel.ToString(); //Restart the server if it was running to begin with if (wasRunning) { kinectCore.StartNetworkKinect(); } } }
//TODO: Subscribe this to the skeletonChanged event and update the GUI with a preview of the skeleton positions public NetworkKinectSettingsControl(int kinectNumber, ref KinectBase.MasterSettings settings, KinectBase.IKinectCore kinect) { if (settings != null) { if (settings.kinectOptionsList[kinectNumber].version == KinectBase.KinectVersion.NetworkKinect) { masterSettings = settings; dynamic tempSettings = settings.kinectOptionsList[kinectNumber]; kinectSettings = (NetworkKinectSettings)tempSettings; kinectID = kinectNumber; kinectCore = (NetworkKinectCore)kinect; uniqueKinectID = kinect.uniqueKinectID; InitializeComponent(); this.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; this.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; //Set the binding on the joint mapping data grid jointMappingDataGrid.ItemsSource = kinectSettings.jointMappings; jointMappingDataGrid.Items.Refresh(); //Subscribe to the skeletonChanged event kinectCore.SkeletonChanged += kinectCore_SkeletonChanged; guiUpdateTimer = new Timer(); guiUpdateTimer.Interval = 1000; guiUpdateTimer.AutoReset = true; guiUpdateTimer.Elapsed += guiUpdateTimer_Elapsed; guiUpdateTimer.Start(); } else { throw new ArgumentException("The provided KinectID is not for a network Kinect sensor."); } } else { throw new ArgumentNullException("settings"); } }
public KinectV1SettingsControl(int kinectNumber, ref KinectBase.MasterSettings settings, KinectBase.IKinectCore kinect) { if (settings != null) { if (settings.kinectOptionsList[kinectNumber].version == KinectBase.KinectVersion.KinectV1) { masterSettings = settings; dynamic tempSettings = settings.kinectOptionsList[kinectNumber]; kinectSettings = (KinectV1Settings)tempSettings; kinectID = kinectNumber; kinectCore = (KinectCoreV1)kinect; kinectCore.AccelerationChanged += kinectCore_AccelerationChanged; uniqueKinectID = kinect.uniqueKinectID; InitializeComponent(); this.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; this.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; //This moved to the wrapper //Grid.SetColumn(this, 2); //this.Visibility = System.Windows.Visibility.Collapsed; if (kinectCore.isXbox360Kinect != null && (bool)kinectCore.isXbox360Kinect) { DisableK4WOnlyOptions(); } } else { throw new ArgumentException("The provided KinectID is not for a Kinect v1 sensor."); } } else { throw new ArgumentNullException("settings"); } }
public void UpdateGUI(KinectBase.MasterSettings newSettings) { if (kinectID.HasValue) { masterSettings = newSettings; dynamic tempSettings = masterSettings.kinectOptionsList[kinectID.Value]; kinectSettings = (KinectV1Settings)tempSettings; //Update the color options switch (kinectSettings.colorImageMode) { case KinectBase.ColorImageFormat.RgbResolution640x480Fps30: { colorResComboBox.SelectedIndex = 0; break; } case KinectBase.ColorImageFormat.RgbResolution1280x960Fps12: { colorResComboBox.SelectedIndex = 1; break; } case KinectBase.ColorImageFormat.InfraredResolution640x480Fps30: { colorResComboBox.SelectedIndex = 2; break; } default: { //If we don't know how to handle a mode, lets just shut it off colorResComboBox.SelectedIndex = 3; break; } } //Update the skeleton settings UseSkeletonCheckBox.IsChecked = kinectSettings.mergeSkeletons; UseRawSkeletonCheckBox.IsChecked = kinectSettings.sendRawSkeletons; XFormRawSkeletonCheckBox.IsChecked = kinectSettings.transformRawSkeletons; SeatedModeCheckBox.IsChecked = kinectSettings.rawSkeletonSettings.isSeatedMode; //Update the depth settings irOnCheckBox.IsChecked = kinectSettings.irON; nearModeCheckBox.IsChecked = kinectSettings.isNearMode; switch (kinectSettings.depthImageMode) { case KinectBase.DepthImageFormat.Resolution320x240Fps30: { depthResComboBox.SelectedIndex = 1; break; } case KinectBase.DepthImageFormat.Resolution80x60Fps30: { depthResComboBox.SelectedIndex = 2; break; } default: { depthResComboBox.SelectedIndex = 0; break; } } //Update the audio settings SendSoundAngleCheckBox.IsChecked = kinectSettings.sendAudioAngle; audioServerTextBox.Text = kinectSettings.audioAngleServerName; audioChannelTextBox.Text = kinectSettings.audioAngleChannel.ToString(); audioBeamSkeletonNumberTextBox.Text = kinectSettings.audioBeamTrackSkeletonNumber.ToString(); switch (kinectSettings.audioTrackMode) { //Note: the enabled/disabled controls don't need to be set manually here because the selected index changed event will still be hit case KinectBase.AudioTrackingMode.Feedback: { audioBeamModeComboBox.SelectedIndex = 1; break; } case KinectBase.AudioTrackingMode.MergedSkeletonX: { audioBeamModeComboBox.SelectedIndex = 2; break; } case KinectBase.AudioTrackingMode.LocalSkeletonX: { audioBeamModeComboBox.SelectedIndex = 3; break; } default: { audioBeamModeComboBox.SelectedIndex = 0; break; } } //Update the acceleration options SendAccelCheckBox.IsChecked = kinectSettings.sendAcceleration; accelServerTextBox.Text = kinectSettings.accelerationServerName; accelXChannelTextBox.Text = kinectSettings.accelXChannel.ToString(); accelYChannelTextBox.Text = kinectSettings.accelYChannel.ToString(); accelZChannelTextBox.Text = kinectSettings.accelZChannel.ToString(); //Update the position options xPosTextBox.Text = kinectSettings.kinectPosition.X.ToString(); yPosTextBox.Text = kinectSettings.kinectPosition.Y.ToString(); zPosTextBox.Text = kinectSettings.kinectPosition.Z.ToString(); yawPosTextBox.Text = kinectSettings.kinectYaw.ToString(); } }
internal static void RunServerInConsole(bool isVerbose, bool autoStart, string startupFile, AvaliableDLLs dlls) { Console.Clear(); Console.WriteLine("Welcome to the Kinect With VR (KVR) Server!"); Console.WriteLine("Press the \"E\" key at any time to exit."); //Notify the user if DLLs are missing if (!dlls.HasKinectV1) { Console.WriteLine("Warning: Kinect v1 support is unavaliable due to missing DLLs"); } if (!dlls.HasKinectV2) { Console.WriteLine("Warning: Kinect v2 support is unavaliable due to missing DLLs"); } if (!dlls.HasNetworkedKinect) { Console.WriteLine("Warning: Networked Kinect support is unavaliable due to missing DLLs"); } KinectBase.MasterSettings settings = new KinectBase.MasterSettings(); try { settings = HelperMethods.LoadSettings(startupFile); } catch { HelperMethods.WriteToLog("Cannot open settings file!"); } ServerCore server = new ServerCore(isVerbose, settings); for (int i = 0; i < server.serverMasterOptions.kinectOptionsList.Count; i++) //Launch the Kinects { if (server.serverMasterOptions.kinectOptionsList[i].version == KinectBase.KinectVersion.KinectV1) { if (dlls.HasKinectV1) { //server.kinects.Add(new KinectV1Core.KinectCoreV1(ref server.serverMasterOptions, false, server.serverMasterOptions.kinectOptionsList[i].kinectID)); server.kinects.Add(new KinectV1Wrapper.Core(ref server.serverMasterOptions, false, server.serverMasterOptions.kinectOptionsList[i].kinectID)); } else { Console.WriteLine("Cannot load Kinect v1 with ID: {0} due to missing DLLs.", server.serverMasterOptions.kinectOptionsList[i].kinectID); } } else if (server.serverMasterOptions.kinectOptionsList[i].version == KinectBase.KinectVersion.KinectV2) { if (dlls.HasKinectV2) { server.kinects.Add(new KinectV2Wrapper.Core(ref server.serverMasterOptions, false, server.serverMasterOptions.kinectOptionsList[i].kinectID)); } else { Console.WriteLine("Cannot load Kinect v2 with ID: {0} due to missing DLLs.", server.serverMasterOptions.kinectOptionsList[i].kinectID); } } else if (server.serverMasterOptions.kinectOptionsList[i].version == KinectBase.KinectVersion.NetworkKinect) { if (dlls.HasNetworkedKinect) { server.kinects.Add(new NetworkKinectWrapper.Core(ref server.serverMasterOptions, false, server.serverMasterOptions.kinectOptionsList[i].kinectID, server.serverMasterOptions.kinectOptionsList[i].uniqueKinectID)); } else { Console.WriteLine("Cannot load network Kinect with ID: {0} due to missing DLLs.", server.serverMasterOptions.kinectOptionsList[i].kinectID); } } else { Console.WriteLine("Kinect number {0} was of an unknown version and could not be opened.", i); } } server.launchServer(); //This will still try to launch with default settings even if the settings load fails bool running = true; while (running) { Thread.Sleep(100); if (Console.KeyAvailable) { ConsoleKeyInfo key = Console.ReadKey(false); if (key.Key == ConsoleKey.E || (key.Key == ConsoleKey.C && key.Modifiers == ConsoleModifiers.Control)) { running = false; } } } Console.WriteLine(); //Write a blank so the next statement has its own line Console.WriteLine("Shutting down the server. Please wait..."); server.stopServer(); NativeInterop.FreeConsole(); }
public void UpdateGUI(KinectBase.MasterSettings newSettings) { if (kinectID.HasValue) { masterSettings = newSettings; dynamic tempSettings = newSettings.kinectOptionsList[kinectID.Value]; kinectSettings = (KinectV2Settings)tempSettings; //Update the color options useColorRadioButton.IsChecked = kinectSettings.useColorPreview; useIRRadionButton.IsChecked = kinectSettings.useIRPreview; //Update the depth options ScaleDepthCheckBox.IsChecked = kinectSettings.scaleDepthToReliableRange; ColorizeDepthCheckBox.IsChecked = kinectSettings.colorizeDepth; //Update skeleton options UseSkeletonCheckBox.IsChecked = kinectSettings.mergeSkeletons; UseRawSkeletonCheckBox.IsChecked = kinectSettings.sendRawSkeletons; XFormRawSkeletonCheckBox.IsChecked = kinectSettings.transformRawSkeletons; //Update audio settings SendSoundAngleCheckBox.IsChecked = kinectSettings.sendAudioAngle; audioServerTextBox.Text = kinectSettings.audioAngleServerName; audioChannelTextBox.Text = kinectSettings.audioAngleChannel.ToString(); audioBeamSkeletonNumberTextBox.Text = kinectSettings.audioBeamTrackSkeletonNumber.ToString(); switch (kinectSettings.audioTrackMode) { //Note: the enabled/disabled controls don't need to be set manually here because the selected index changed event will still be hit case KinectBase.AudioTrackingMode.Feedback: { audioBeamModeComboBox.SelectedIndex = 1; break; } case KinectBase.AudioTrackingMode.MergedSkeletonX: { audioBeamModeComboBox.SelectedIndex = 2; break; } case KinectBase.AudioTrackingMode.LocalSkeletonX: { audioBeamModeComboBox.SelectedIndex = 3; break; } default: { audioBeamModeComboBox.SelectedIndex = 0; break; } } //Update the position options xPosTextBox.Text = kinectSettings.kinectPosition.X.ToString(); yPosTextBox.Text = kinectSettings.kinectPosition.Y.ToString(); zPosTextBox.Text = kinectSettings.kinectPosition.Z.ToString(); yawPosTextBox.Text = kinectSettings.kinectYaw.ToString(); pitchPosTextBox.Text = kinectSettings.kinectPitch.ToString(); rollPosTextBox.Text = kinectSettings.kinectRoll.ToString(); } }