Depth-D3D C++ Sample

Kinect for Windows 1.5, 1.6, 1.7, 1.8

To compile this sample, you must have the DirectX SDK installed. To run this sample, you must have the DirectX End-User Runtime installed. (To download either, see Software Requirements.) If you compile or run the sample without the required SDK or runtime installed, the sample notifies you there is a missing DLL and the sample exits.


When you run this sample, you see the following:

  • The depth data is captured and displayed as a grayscale image of the distance between the sensor and whatever is in front of the sensor. The sample displays pixels within the interaction space shaded gray or white; pixels outside of the interaction space are colored black.
The Sample Uses the Following APIsTo Do This
NuiImageResolutionToSize FunctionGet the width and height of the depth frame.
NuiGetSensorCount FunctionGet the number of sensors that are ready for use.
NuiCreateSensorByIndex Function and INuiSensor interfaceCreate an interface that represents a connected sensor.
INuiSensor::NuiStatus MethodCheck the sensor status to see if the sensor is connected.
INuiSensor::NuiInitialize Method and NUI_IMAGE_TYPE_DEPTH_AND_PLAYER_INDEX constantInitialize the sensor to stream out depth data.
INuiSensor::NuiImageStreamSetImageFrameFlags Method and NUI_IMAGE_STREAM_FLAG_ENABLE_NEAR_MODE constantSet depth data range to near range.
CreateEvent FunctionCreate an event that will be signaled when depth data is available by returning an event handle.
INuiSensor::NuiImageStreamOpen Method, NUI_IMAGE_TYPE_DEPTH constant, NUI_IMAGE_RESOLUTION_640x480 constant, and the event handleOpen a depth stream to receive depth data.
INuiSensor::NuiImageStreamGetNextFrame MethodGet the next frame of color data (using the color data event handle).
INuiFrameTexture::LockRect Method and NUI_LOCKED_RECT structureLock the texture to prepare for saving texture data.
INuiFrameTexture::UnlockRect MethodUnlock the texture after saving the texture data.
INuiSensor::NuiImageStreamReleaseFrame MethodRelease each frame of depth data after saving it.
INuiSensor::Release MethodRelease the sensor when you exit the application.
NuiShutdown functionShut down the sensor.

To run a sample you must have the Kinect for Windows SDK installed. To compile a sample, you must have the developer toolkit installed. The latest SDK and developer toolkit are available on the developer download page. If you need help installing the toolkit, look on this page: To Install the SDK and Toolkit. The toolkit includes a sample browser, which you can use to launch a sample or download it to your machine. To open the sample browser, click Start > All Programs > Kinect for Windows SDK [version number] > Developer Toolkit Browser.

If you need help loading a sample in Visual Studio or using Visual Studio to compile, run, or debug, see Opening, Building, and Running Samples in Visual Studio.

Community Additions