简体   繁体   中英

Programmatically detect Kinect type (Xbox or PC)

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.

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;
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM