Question

This should be pretty simple, but a quick Google didn't turn up anything useful and I don't see any members on Microsoft.Kinect.KinectSensor that look helpful.

I'm writing an application that uses a Kinect for some gesture control stuff. It works fine with either the Xbox or PC version of the Kinect, but the Xbox version doesn't support "near mode", so the user has to be a certain distance back. I'd like to let the user know this when they launch the program.

Is it possible to detect which version of the Kinect has been connected? I get a message in Visual Studio's debug output telling me that I've connected an Xbox version, so it must be checking somewhere, but I don't see anywhere that this information is made available to my code.

Was it helpful?

Solution

When you try to use a feature that the Xbox version does not support, an InvalidOperation is thrown. When you catch that exception, you can be sure that a Xbox kinect is connected.

 try
 {
   sensor.DepthStream.Range = DepthRange.Near;
   sensor.SkeletonStream.EnableTrackingInNearRange = true;
 }
 catch (InvalidOperationException)
 {
   // Non Kinect for Windows devices do not support Near mode, so reset back to default mode.
   sensor.DepthStream.Range = DepthRange.Default;
   sensor.SkeletonStream.EnableTrackingInNearRange = false;
 }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top