OpenNI 1.5.7
Basic Functions: initialize, create a node and read data

The following code illustrates the basic functionality of OpenNI. It initializes a Context object, creates a single Depth node, and reads data from it.

xn::Context context;
// Initialize context object
nRetVal = context.Init();
// TODO: check error code
// Create a DepthGenerator node
nRetVal = depth.Create(context);
// TODO: check error code
// Make it start generating data
nRetVal = context.StartGeneratingAll();
// TODO: check error code
// Main loop
while (bShouldRun)
{
// Wait for new data to be available
nRetVal = context.WaitOneUpdateAll(depth);
if (nRetVal != XN_STATUS_OK)
{
printf("Failed updating data: %s\n", xnGetStatusString(nRetVal));
continue;
}
// Take current depth map
const XnDepthPixel* pDepthMap = depth.GetDepthMap();
// TODO: process depth map
}
// Clean-up
context.Shutdown();
XnUInt32 XnStatus
Definition XnStatus.h:33
#define XN_STATUS_OK
Definition XnStatus.h:36
XN_C_API const XnChar *XN_C_DECL xnGetStatusString(const XnStatus Status)
XnUInt16 XnDepthPixel
Definition XnTypes.h:278
Definition XnCppWrapper.h:8621
XnStatus WaitOneUpdateAll(ProductionNode &node)
Updates all generator nodes in the context to their latest available data, first waiting for a specif...
Definition XnCppWrapper.h:9446
XnStatus Init()
Builds the context's general software environment.
Definition XnCppWrapper.h:8734
XnStatus StartGeneratingAll()
Ensures all created generator nodes are generating data.
Definition XnCppWrapper.h:9188
Definition XnCppWrapper.h:4721
const XnDepthPixel * GetDepthMap() const
Gets the current depth-map. This map is updated after a call to xnWaitAndUpdateData()....
Definition XnCppWrapper.h:4765
XnStatus Create(Context &context, Query *pQuery=NULL, EnumerationErrors *pErrors=NULL)
Creates a DepthGenerator node from available production node alternatives.
Definition XnCppWrapper.h:9828