Identify Kinect device index from device instance id

In one of our previous tip ( Using Kinect Instance Id to Initialize the Kinect Sensor ) we have seen how we can initialize Kinect device using the instance id. In this tip, you will see how we can use the instance id to get the device index position.

First of all, you can use below code snippet to get the DeviceConnectionId

inectSensor sensor = KinectSensor.KinectSensors [@" USUSB\VID_0409&PID_005A\6&35F09B95&0&3"];
int deviceConnectionID = sensor.DeviceConnectionId

Now, you can refer to the device using the deviceConnectionID as shown in the following code block:

int currentPosition = 0;
var collection = KinectSensor.KinectSensors.Where(item => item.DeviceConnectionId == deviceConnectionID );
var indexCollection = from item in collection
let row = currentPosition++
select new { SensorObject = item, SensorIndex = row };

If  you have only one sensor is connected, the index should be 0. You can use the above code block for multiple Kinect sensors as well.
Device Index From Kinect InstaceID

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.