How to check if any Kinect device is connected with system ?

If you are dealing with Kinect based application, It is always good practice to first check if there is any Kinect sensor connected with the PC before doing any operation with KinectSensor objects. The KinectSensors holds the reference of all connected sensors and as this is a collection, it has a Count property.  You can use the KinectSensors.Count to check the number of device. The device count will more than 0, only if there is one or more device is connected.

int deviceCount = KinectSensor.KinectSensors.Count;
if (deviceCount > 0)
{

this.sensor = KinectSensor.KinectSensors[0];
// Rest operation here
}
else
{
// No sensor connected.
}

Consider, you have one device connected, so you will get reference of connected sensor as shown in below code snippet.

this.sensor = KinectSensor.KinectSensors[0];

Once you have the Sensor object of the Kinect device, invoke KinectSensor.Start() method to start the sensor.

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.

2 Comments to “How to check if any Kinect device is connected with system ?”

Comments are closed.