![]() |
OpenNI 1.5.4
|
<b>Source file:</b> Click the following link to view the source code file: - NiSimpleRead.cpp This section describes the SimpleRead sample program.
The declaration block at the top of the program declares a Context object, a ScriptNode object, and an EnumerationErrors object. The context is workspace where the application builds an OpenNI production graph. The script node object loads and contains the OpenNI script and is the base node for the production graph. The production graph is a network of production nodes and is the principal OpenNI object model. The EnumerationErrors and XnStatus object types are for collecting errors from any of the OpenNI functions. Also declared is an OpenNI status flag for collecting return values from method calls.
The @ref xn::Context::InitFromXmlFile() "InitFromXmlFile()" method is a shorthand combination of two other initialization methods — @ref xn::Context::Init() "Init()" and then @ref xn::Context::RunXmlScriptFromFile() "RunXmlScriptFromFile()" — which initializes the context object and then creates a production graph from an XML file. The XML script file describes all the nodes you want to create. For each node description in the XML file, this method creates a node in the production graph.
Summary: This code is some more verification code. This time it checks that OpenNI found at least one node definition in the script file. The program continues execution only if at least one node definition if found.
Assuming that the above call to @ref xn::Context::InitFromXmlFile() "InitFromXmlFile()" succeeded, a production graph is then created. The @ref xn::Context::FindExistingNode() "FindExistingNode()" method in the following code block tries to get a reference to any one of the production nodes. This call specifies XN_NODE_TYPE_DEPTH to get a reference to a @ref xn::DepthGenerator "DepthGenerator" node. A DepthGenerator node generates a depth map as an array of pixels, where each pixel is a depth value representing a distance from the sensor in millimeters. A reference to the node is returned in the depth parameter.
The following declaration block initializes the FPS Calculator.
The following statement declares a metadata object to provide a @ref glos_frame_object "frame object" for the @ref xn::DepthGenerator node. A @ref dict_gen_node "generator node's" @ref glos_frame_object "frame object" contains a generated data frame and all its associated properties. This frame object, comprising the data frame and its properties, is accessible through the node's metadata object.
The main program loop repeatedly updates the data available in the node for output, and then gets the frame object (via the metadata object). The program then calculates the mid-point of the scene's 2D (two-dimensional) area.
the @ref xn::Context::WaitOneUpdateAll() "WaitOneUpdateAll()" method in the following statement updates all generator nodes in the context that have new data available, first waiting for a specified node to have new data available. The application can then get the data (for example, using a metadata GetData() method). This method has a timeout.
The following statement gets the latest generated depth @ref glos_frame_object "frame object", saving it as a metadata object.
The following print statement accesses the frame data, its ID, and the frame data's associated configuration, The frame ID is the ID of the frame object. Frame IDs are a sequential unique number with a wrap around. This method is inherited from the OutputMetaData class.
In the above, XRes() and YRes() are the dimensions of the FOV in the scene. The call to depthMD() accesses a depth pixel through an X,Y coordinate. By calculating XRes()/2 and YRes()/2, this accesses the middle pixel.