OpenNI 1.5.7
Configuring nodes

An application would usually want to fully configure a node before it starts streaming data. For that reason, OpenNI defines a flow in which configuration can take place, and once all configuration is set, the node xn::Generator::StartGenerating() method can be called to make it start streaming the data.

The following code creates a depth generator, configures it to VGA resolution, 30 FPS, and then starts it:

// Create a DepthGenerator node
nRetVal = depth.Create(context);
// TODO: check error code
XnMapOutputMode outputMode;
outputMode.nXRes = 640;
outputMode.nYRes = 480;
outputMode.nFPS = 30;
nRetVal = depth.SetMapOutputMode(outputMode);
// TODO: check error code
// We're done configuring it. 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
}
XnMapOutputMode::nYRes
XnUInt32 nYRes
Definition: XnTypes.h:440
xnGetStatusString
const XN_C_API XnChar *XN_C_DECL xnGetStatusString(const XnStatus Status)
XN_STATUS_OK
#define XN_STATUS_OK
Definition: XnStatus.h:36
XnMapOutputMode::nXRes
XnUInt32 nXRes
Definition: XnTypes.h:438
xn::Context::StartGeneratingAll
XnStatus StartGeneratingAll()
Ensures all created generator nodes are generating data.
Definition: XnCppWrapper.h:9207
xn::DepthGenerator
Definition: XnCppWrapper.h:4739
XnDepthPixel
XnUInt16 XnDepthPixel
Definition: XnTypes.h:278
xn::DepthGenerator::GetDepthMap
const XnDepthPixel * GetDepthMap() const
Gets the current depth-map. This map is updated after a call to xnWaitAndUpdateData()....
Definition: XnCppWrapper.h:4784
XnMapOutputMode
Definition: XnTypes.h:435
xn::DepthGenerator::Create
XnStatus Create(Context &context, Query *pQuery=NULL, EnumerationErrors *pErrors=NULL)
Creates a DepthGenerator node from available production node alternatives.
Definition: XnCppWrapper.h:9847
XnMapOutputMode::nFPS
XnUInt32 nFPS
Definition: XnTypes.h:442
xn::Context::WaitOneUpdateAll
XnStatus WaitOneUpdateAll(ProductionNode &node)
Updates all generator nodes in the context to their latest available data, first waiting for a specif...
Definition: XnCppWrapper.h:9465
xn::MapGenerator::SetMapOutputMode
XnStatus SetMapOutputMode(const XnMapOutputMode &OutputMode)
Sets the current map output mode of the generator node.
Definition: XnCppWrapper.h:4338