XnStatus ConfigureGenerators(const RecConfiguration& config, xn::Context& context, xn::DepthGenerator& depthGenerator, xn::ImageGenerator& imageGenerator) { XnStatus nRetVal = XN_STATUS_OK; xn::EnumerationErrors errors; // Configure the depth, if needed if (config.bRecordDepth) { nRetVal = context.CreateAnyProductionTree(XN_NODE_TYPE_DEPTH, NULL, depthGenerator, &errors); CHECK_RC_ERR(nRetVal, "Create Depth", errors); nRetVal = depthGenerator.SetMapOutputMode(*config.pDepthMode); CHECK_RC(nRetVal, "Set Mode"); if (config.bMirrorIndicated && depthGenerator.IsCapabilitySupported(XN_CAPABILITY_MIRROR)) { depthGenerator.GetMirrorCap().SetMirror(config.bMirror); } // Set Hole Filter depthGenerator.SetIntProperty("HoleFilter", TRUE); } // Configure the image, if needed if (config.bRecordImage) { nRetVal = context.CreateAnyProductionTree(XN_NODE_TYPE_IMAGE, NULL, imageGenerator, &errors); CHECK_RC_ERR(nRetVal, "Create Image", errors); nRetVal = imageGenerator.SetMapOutputMode(*config.pImageMode); CHECK_RC(nRetVal, "Set Mode"); if (config.bMirrorIndicated && imageGenerator.IsCapabilitySupported(XN_CAPABILITY_MIRROR)) { imageGenerator.GetMirrorCap().SetMirror(config.bMirror); } } // Configuration for when there are both streams if (config.bRecordDepth && config.bRecordImage) { // Registration if (config.bRegister && depthGenerator.IsCapabilitySupported(XN_CAPABILITY_ALTERNATIVE_VIEW_POINT)) { nRetVal = depthGenerator.GetAlternativeViewPointCap().SetViewPoint(imageGenerator); CHECK_RC(nRetVal, "Registration"); } // Frame Sync if (config.bFrameSync && depthGenerator.IsCapabilitySupported(XN_CAPABILITY_FRAME_SYNC)) { if (depthGenerator.GetFrameSyncCap().CanFrameSyncWith(imageGenerator)) { nRetVal = depthGenerator.GetFrameSyncCap().FrameSyncWith(imageGenerator); CHECK_RC(nRetVal, "Frame sync"); } } } return XN_STATUS_OK; }
void StartCapture() { char recordFile[256] = {0}; time_t rawtime; struct tm *timeinfo; time(&rawtime); timeinfo = localtime(&rawtime); XnUInt32 size; xnOSStrFormat(recordFile, sizeof(recordFile)-1, &size, "%d_%02d_%02d[%02d_%02d_%02d].oni", timeinfo->tm_year + 1900, timeinfo->tm_mon + 1, timeinfo->tm_mday, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); if (g_pRecorder != NULL) { StopCapture(); } XnStatus nRetVal = XN_STATUS_OK; g_pRecorder = new xn::Recorder; g_Context.CreateAnyProductionTree(XN_NODE_TYPE_RECORDER, NULL, *g_pRecorder); START_CAPTURE_CHECK_RC(nRetVal, "Create recorder"); nRetVal = g_pRecorder->SetDestination(XN_RECORD_MEDIUM_FILE, recordFile); START_CAPTURE_CHECK_RC(nRetVal, "set destination"); nRetVal = g_pRecorder->AddNodeToRecording(g_DepthGenerator, XN_CODEC_16Z_EMB_TABLES); START_CAPTURE_CHECK_RC(nRetVal, "add node"); g_bRecord = true; }