KinectBridgeWithMATLABBasics D2D C++ Sample

Kinect for Windows 1.7, 1.8

To compile and run this sample, you must have MATLAB R2012a or R2012b installed. To find out more about MATLAB see the MathWorks web page and look for the Try or Buy link.


This sample shows how to perform numerical computation and visualization using MATLAB functions on video and depth data from a sensor.

The Sample Uses the Following APIsTo Do This
NuiImageResolutionToSize functionGet the width and height of the depth frame.
NuiGetSensorCount function Get 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, the event handleOpen a depth stream to receive depth data.
CreateBitmap functionCreate a bitmap for the color data.
UpdateBitmap functionSave the color image in a bitmap for drawing.
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.

KinectHelper is an abstract base class that holds functions to communicate with the Kinect runtime to get color and depth data, one frame at a time. MatlabKinectHelper is a concrete implementation of the KinectHelper class that implements functionality to convert the color and depth data from the sensor into RGB matrices used by MATLAB. These classes are only available in this sample and are not part of the Kinect for Windows SDK or Toolkit.

The Sample Uses the Following Additional Classes and MethodsTo Do This
KinectHelper::SetDepthFrameResolution method Set the resolution of the depth frame.
KinectHelper::IsInitialized method Update a frame only if it has been initialized.
KinectHelper::UpdateColorFrame method Get a new color frame.
KinectHelper::GetColorImage method Get the color image.
KinectHelper::SetColorFrameResolution method Set the resolution of the color frame.
KinectHelper::GetColorFrameSize method Initialize the color MATLAB matrix

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.

In This Section

Community Additions