/* void openni::VideoMode::setResolution() Setter function for the resolution of this VideoMode. Application use of this function is not recommended. Instead, use SensorInfo::getSupportedVideoModes() to obtain a list of valid video modes -- cited from OpenNI2 help. setResolution() is not recommended. */ bool setONI2StreamMode(openni::VideoStream& stream, int w, int h, int fps, openni::PixelFormat format){ //std::cout << "Ask mode: " << w << "x" << h << " " << fps << " fps. format " << format << std::endl; bool found = false; const openni::Array<openni::VideoMode>& modes = stream.getSensorInfo().getSupportedVideoModes(); for(int i = 0, i_end = modes.getSize();i < i_end;++i){ // std::cout << "Mode: " << modes[i].getResolutionX() << "x" << modes[i].getResolutionY() << " " << modes[i].getFps() << " fps. format " << modes[i].getPixelFormat() << std::endl; if(modes[i].getResolutionX() != w){ continue; } if(modes[i].getResolutionY() != h){ continue; } if(modes[i].getFps() != fps){ continue; } if(modes[i].getPixelFormat() != format){ continue; } openni::Status rc = stream.setVideoMode(modes[i]); if(rc != openni::STATUS_OK){ return false; } return true; } return false; }
bool setONI2StreamMode(openni::VideoStream& stream, int w, int h, int fps, openni::PixelFormat format){ /* void openni::VideoMode::setResolution() Setter function for the resolution of this VideoMode. Application use of this function is not recommended. Instead, use SensorInfo::getSupportedVideoModes() to obtain a list of valid video modes -- cited from OpenNI2 help. setResolution() is not recommended. */ bool found = false; const openni::Array<openni::VideoMode>& modes = stream.getSensorInfo().getSupportedVideoModes(); for(int i = 0, i_end = modes.getSize();i < i_end;++i){ if(modes[i].getResolutionX() != w){ continue; } if(modes[i].getResolutionY() != h){ continue; } if(modes[i].getPixelFormat() != format){ continue; } openni::Status rc = stream.setVideoMode(modes[i]); if(rc != openni::STATUS_OK){ printf("%s:Couldn't find RGB stream:\n%s\n", __FUNCTION__, openni::OpenNI::getExtendedError()); return false; } return true; } return false; }
void setDepthVideoMode(int mode) { bool bIsStreamOn = g_bIsDepthOn; if (bIsStreamOn) { g_bIsDepthOn = false; g_depthStream.stop(); } g_depthStream.setVideoMode(g_depthSensorInfo->getSupportedVideoModes()[mode]); if (bIsStreamOn) { g_depthStream.start(); g_bIsDepthOn = true; } }
void setIRVideoMode(int mode) { bool bIsStreamOn = g_bIsIROn; if (bIsStreamOn) { g_bIsIROn = false; g_irStream.stop(); } g_irFrame.release(); g_irStream.setVideoMode(g_irSensorInfo->getSupportedVideoModes()[mode]); if (bIsStreamOn) { g_irStream.start(); g_bIsIROn = true; } }
void open(const char* uri) { if (device.open(uri) != openni::STATUS_OK) BOOST_THROW_EXCEPTION(GrabberException("Failed to open device") << GrabberException::ErrorInfo(openni::OpenNI::getExtendedError())); if (color_stream.create(device, openni::SENSOR_COLOR) != openni::STATUS_OK) BOOST_THROW_EXCEPTION(GrabberException("Failed to create color stream") << GrabberException::ErrorInfo(openni::OpenNI::getExtendedError())); openni::VideoMode color_mode; color_mode.setFps(30); color_mode.setResolution(color_image_resolution.width, color_image_resolution.height); color_mode.setPixelFormat(openni::PIXEL_FORMAT_RGB888); color_stream.setVideoMode(color_mode); color_image_size = color_image_resolution.width * color_image_resolution.height * 3; color_stream.setMirroringEnabled(false); if (color_stream.start() != openni::STATUS_OK) { color_stream.destroy(); BOOST_THROW_EXCEPTION(GrabberException("Failed to start color stream") << GrabberException::ErrorInfo(openni::OpenNI::getExtendedError())); } streams.push_back(&color_stream); auto control = device.getPlaybackControl(); if (control != nullptr) { // This is a file, make sure we get every frame control->setSpeed(-1.0f); control->setRepeatEnabled(false); num_frames = control->getNumberOfFrames(color_stream); is_file = true; if (num_frames == -1) BOOST_THROW_EXCEPTION(GrabberException("Unable to determine number of frames in ONI file")); } }
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: