openni录制文件

#include "stdafx.h"
#include
<XnCppWrapper.h>

using namespace xn;
#define SAMPLE_XML_PATH "e:/SamplesConfig.xml"
#define CHECK_RC(rc,what) \
if (rc != XN_STATUS_OK) \
{ \
printf(
"%s 失败!: %s\n", what, xnGetStatusString(rc)); \
\
} \
else \
{ \
printf(
"%s 成功!: %s\n", what, xnGetStatusString(rc)); \
\
} \


int _tmain(int argc, _TCHAR* argv[])
{

XnStatus nRetVal
= XN_STATUS_OK;
xn::Context context;
xn::ImageGenerator image;
xn::DepthGenerator depth;
xn::Recorder record;

nRetVal
=context.InitFromXmlFile(SAMPLE_XML_PATH);
CHECK_RC(nRetVal,
"Init");
nRetVal
=context.FindExistingNode(XN_NODE_TYPE_IMAGE,image);
CHECK_RC(nRetVal,
"get image ");
nRetVal
=context.FindExistingNode(XN_NODE_TYPE_DEPTH,depth);
CHECK_RC(nRetVal,
"get depth");

context.StartGeneratingAll();
XnMapOutputMode mode;
mode.nXRes
= XN_VGA_X_RES;
mode.nYRes
= XN_VGA_Y_RES;
mode.nFPS
= 30;

nRetVal
= depth.SetMapOutputMode( mode );
CHECK_RC(nRetVal,
"config depth generator");
nRetVal
= image.SetMapOutputMode( mode );
CHECK_RC(nRetVal,
"config image generator");


record.Create(context);
record.SetDestination(XN_RECORD_MEDIUM_FILE,
"F:/kinect_scene.ONI");
record.AddNodeToRecording(image,XN_CODEC_JPEG);
record.AddNodeToRecording(depth,XN_CODEC_16Z_EMB_TABLES);

while(true)
{
nRetVal
=context.WaitAndUpdateAll();

if(nRetVal!=XN_STATUS_OK)
{
printf(
"failed to update\n");
}
if (xnOSWasKeyboardHit())
{
char c = xnOSReadCharFromInput();
if(27==c)break;
}

nRetVal
=record.Record();
CHECK_RC(nRetVal,
"recording ");
}
record.Unref();
context.Shutdown();

return 0;
}
注意录制图像节点的时候编码方式得采用XN_CODEC_JPEG

  

你可能感兴趣的:(openni)