Depth with Color-D3D C++ Sample

Kinect for Windows 1.5, 1.6, 1.7, 1.8


When you run this sample, you see the following:

  • The depth data is captured and displayed; this is a continually streaming grayscale image of the distance between the sensor and whatever the Kinect is pointed at. The camera can see pixels inside of the interaction space, which are colored shades of gray or white; pixels that are outside of the interaction space are colored black.
The Sample Uses the Following APIsTo Do This
NuiImageResolutionToSize functionUse this two times to get the width and height of the depth frame and to get the width and height of the color 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 and NUI_INITIALIZE_FLAG_USES_COLOR constantsInitialize the sensor to stream out depth and color data.
INuiSensor::NuiImageStreamSetImageFrameFlags method and NUI_IMAGE_STREAM_FLAG_ENABLE_NEAR_MODE constantSet depth data range to near range.
CreateEvent functionCreate two events, one for depth data and one for color data. Each event will be signaled when new data (depth or color) 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::NuiImageStreamOpen method, NUI_IMAGE_TYPE_COLOR constant, NUI_IMAGE_RESOLUTION_640x480 constant, and the event handleOpen a color stream to receive color data.
INuiSensor::NuiImageStreamGetNextFrame method and the depth data event handleGet the next frame of depth data (using the depth data event handle).
INuiSensor::NuiImageStreamGetNextFrame method and the color data event handleGet the next frame of color data (using the depth 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 methodUse this twice to release each frame of data (depth and color) 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