I am writing my first Kinect Application with the following user interface.
I am following this tutorial for more context.
The concept of the application consists only to integrate the camera of the Kinect into the desktop application. I think it might be important to note that I have a Kinect for Xbox One and its corresponding adapter using the Kinect SDK and Toolkit Version 1.8
The code for the button event handling is the following is the following
private void btnStream_Click(object sender, EventArgs e)
{
if (btnStream.Text == "Stream")
{
if (KinectSensor.KinectSensors.Count > 0)
{
ksensor = KinectSensor.KinectSensors[0];
KinectSensor.KinectSensors.StatusChanged += KinectSensors_StatusChanged;
}
ksensor.Start();
lblConnectionID.Text = ksensor.DeviceConnectionId;
}
else
{
if (ksensor != null && ksensor.IsRunning)
{
ksensor.Stop();
this.btnStream.Text = "Stream";
this.pbStream.Image = null;
}
}
}
private void KinectSensors_StatusChanged(object sender, StatusChangedEventArgs e)
{
this.lblStatus.Text = ksensor.Status.ToString();
}
and I get the following error from Visual Studio
An unhandled exception of type 'System.NullReferenceException' occurred in WindowsFormsApplication1.exe
Additional information: Object reference not set to an instance of an object.
The error is pointing to this line of code:
ksensor.Start();
It is guaranteed that the ksensor variable is declared as follows:
private KinectSensor ksensor;
My question is why is my variable KinectSensor.KinectSensors.Count
probably 0 while I am supposed to have 1 as the return value? Does my application not recognize my kinnect?