void toggleFrameSync(int) { if (g_bFrameSyncOn) { g_device.setDepthColorSyncEnabled(false); displayMessage("Frame sync off"); } else { openni::Status rc = g_device.setDepthColorSyncEnabled(true); if (rc != openni::STATUS_OK) { displayMessage("Can't frame sync"); return; } displayMessage("Frame sync on"); } g_bFrameSyncOn = !g_bFrameSyncOn; }
int SensorOpenNI::initialize() { LOG(INFO) << "Initializing OpenNI"; ///< force shutdown before starting!! kinect::OpenNI::shutdown(); kinect::Status rc; rc = kinect::STATUS_OK; /// Fetch the device URI to pass to Device::open() const char* deviceURI = kinect::ANY_DEVICE; /// Initialize the device rc = kinect::OpenNI::initialize(); if(rc!=kinect::STATUS_OK) { mDebug()<<"Initialization Errors (if any): "<< kinect::OpenNI::getExtendedError(); kinect::OpenNI::shutdown(); exit(0); } /// Open the device using the previously fetched device URI rc = device.open(deviceURI); if (rc != kinect::STATUS_OK) { mDebug()<<"Device open failed: "<<kinect::OpenNI::getExtendedError(); kinect::OpenNI::shutdown(); exit(0); } /// Create the depth stream rc = g_depthStream.create(device, kinect::SENSOR_DEPTH); if (rc == kinect::STATUS_OK) { /// start the depth stream, if its creation was successful rc = g_depthStream.start(); if (rc != kinect::STATUS_OK) { mDebug()<<"Couldn't start depth stream: "<<kinect::OpenNI::getExtendedError(); g_depthStream.destroy(); exit(0); } } else { mDebug()<<"Couldn't find depth stream: "<<kinect::OpenNI::getExtendedError(); exit(0); } if (!g_depthStream.isValid()) { mDebug()<<"No valid depth streams. Exiting"; kinect::OpenNI::shutdown(); exit(0); } /// Create the color stream rc = g_colorStream.create(device, kinect::SENSOR_COLOR); if (rc == kinect::STATUS_OK) { /// start the color stream, if its creation was successful rc = g_colorStream.start(); if (rc != kinect::STATUS_OK) { mDebug()<<"Couldn't start color stream: "<<kinect::OpenNI::getExtendedError(); g_colorStream.destroy(); exit(0); } } else { mDebug()<<"Couldn't find color stream: "<<kinect::OpenNI::getExtendedError(); exit(0); } if (!g_colorStream.isValid()) { mDebug()<<"No valid color streams. Exiting"; kinect::OpenNI::shutdown(); exit(0); } /// Configure resolutions { /// Attempt to set for depth { kinect::VideoMode mode = g_depthStream.getVideoMode(); if(((int)camera->FPS())==60) mode.setFps(60); else mode.setFps(30); mode.setResolution(camera->width(), camera->height()); rc = g_depthStream.setVideoMode(mode); if (rc != kinect::STATUS_OK) std::cerr << "error setting video mode (depth)" << std::endl; } /// Attempt to set for color { kinect::VideoMode mode = g_colorStream.getVideoMode(); if(((int)camera->FPS())==60) mode.setFps(60); else mode.setFps(30); mode.setFps(30); ///< @todo check!!! mode.setResolution(camera->width(), camera->height()); rc = g_colorStream.setVideoMode(mode); if (rc != kinect::STATUS_OK) std::cerr << "error setting video mode (color)" << std::endl; } } #ifdef THIS_CAUSES_INIT_STALLS /// Enable depth/color frame synchronization rc = device.setDepthColorSyncEnabled(true); if (rc != kinect::STATUS_OK) { qDebug()<<"Could not synchronise device"; // VGA Kinect always seems to shut down here kinect::OpenNI::shutdown(); exit(0); } #endif /// Camera settings kinect::CameraSettings* settings = g_colorStream.getCameraSettings(); settings->setAutoExposureEnabled(true); settings->setAutoWhiteBalanceEnabled(true); /// Fetch the camera intrinsics #if 0 float w = g_depthStream.getVideoMode().getResolutionX();protected: