35 #include <boost/lexical_cast.hpp> 36 #include <boost/algorithm/string/replace.hpp> 43 #include <boost/shared_ptr.hpp> 44 #include <boost/make_shared.hpp> 53 ir_video_started_(
false),
54 color_video_started_(
false),
55 depth_video_started_(
false),
56 image_registration_activated_(
false),
57 use_device_time_(
false)
59 openni::Status rc = openni::OpenNI::initialize();
60 if (rc != openni::STATUS_OK)
63 openni_device_ = boost::make_shared<openni::Device>();
65 if (device_URI.length() > 0)
67 rc = openni_device_->open(device_URI.c_str());
71 rc = openni_device_->open(openni::ANY_DEVICE);
74 if (rc != openni::STATUS_OK)
77 device_info_ = boost::make_shared<openni::DeviceInfo>();
78 *device_info_ = openni_device_->getDeviceInfo();
80 ir_frame_listener = boost::make_shared<OpenNI2FrameListener>();
81 color_frame_listener = boost::make_shared<OpenNI2FrameListener>();
82 depth_frame_listener = boost::make_shared<OpenNI2FrameListener>();
124 boost::replace_all(ID_str,
"/",
"");
125 boost::replace_all(ID_str,
".",
"");
126 boost::replace_all(ID_str,
"@",
"");
138 float focal_length = 0.0f;
143 focal_length = (float)output_y_resolution / (2 * tan(stream->getVerticalFieldOfView() / 2));
151 float focal_length = 0.0f;
156 focal_length = (float)output_y_resolution / (2 * tan(stream->getVerticalFieldOfView() / 2));
164 float focal_length = 0.0f;
169 focal_length = (float)output_y_resolution / (2 * tan(stream->getVerticalFieldOfView() / 2));
177 float baseline = 0.075f;
180 if (stream && stream->isPropertySupported(XN_STREAM_PROPERTY_EMITTER_DCMOS_DISTANCE))
182 double baseline_meters;
183 stream->getProperty(XN_STREAM_PROPERTY_EMITTER_DCMOS_DISTANCE, &baseline_meters);
184 baseline =
static_cast<float>(baseline_meters * 0.01f);
193 bool supported =
false;
195 std::vector<OpenNI2VideoMode>::const_iterator it =
ir_video_modes_.begin();
196 std::vector<OpenNI2VideoMode>::const_iterator it_end =
ir_video_modes_.end();
198 while (it != it_end && !supported)
200 supported = (*it == video_mode);
211 bool supported =
false;
216 while (it != it_end && !supported)
218 supported = (*it == video_mode);
229 bool supported =
false;
234 while (it != it_end && !supported)
236 supported = (*it == video_mode);
265 stream->setMirroringEnabled(
false);
279 stream->setMirroringEnabled(
false);
291 stream->setMirroringEnabled(
false);
373 const openni::SensorInfo& sensor_info = stream->getSensorInfo();
389 const openni::SensorInfo& sensor_info = stream->getSensorInfo();
405 const openni::SensorInfo& sensor_info = stream->getSensorInfo();
415 return openni_device_->isImageRegistrationModeSupported(openni::IMAGE_REGISTRATION_DEPTH_TO_COLOR);
425 openni::Status rc =
openni_device_->setImageRegistrationMode(openni::IMAGE_REGISTRATION_DEPTH_TO_COLOR);
426 if (rc != openni::STATUS_OK)
427 THROW_OPENNI_EXCEPTION(
"Enabling image registration mode failed: \n%s\n", openni::OpenNI::getExtendedError());
431 openni::Status rc =
openni_device_->setImageRegistrationMode(openni::IMAGE_REGISTRATION_OFF);
432 if (rc != openni::STATUS_OK)
433 THROW_OPENNI_EXCEPTION(
"Enabling image registration mode failed: \n%s\n", openni::OpenNI::getExtendedError());
440 openni::Status rc =
openni_device_->setDepthColorSyncEnabled(enabled);
441 if (rc != openni::STATUS_OK)
442 THROW_OPENNI_EXCEPTION(
"Enabling depth color synchronization failed: \n%s\n", openni::OpenNI::getExtendedError());
453 openni::VideoMode video_mode = stream->getVideoMode();
471 openni::VideoMode video_mode = stream->getVideoMode();
489 openni::VideoMode video_mode = stream->getVideoMode();
506 const openni::Status rc = stream->setVideoMode(videoMode);
507 if (rc != openni::STATUS_OK)
519 const openni::Status rc = stream->setVideoMode(videoMode);
520 if (rc != openni::STATUS_OK)
532 const openni::Status rc = stream->setVideoMode(videoMode);
533 if (rc != openni::STATUS_OK)
544 openni::CameraSettings* camera_seeting = stream->getCameraSettings();
547 const openni::Status rc = camera_seeting->setAutoExposureEnabled(enable);
548 if (rc != openni::STATUS_OK)
560 openni::CameraSettings* camera_seeting = stream->getCameraSettings();
563 const openni::Status rc = camera_seeting->setAutoWhiteBalanceEnabled(enable);
564 if (rc != openni::STATUS_OK)
577 openni::CameraSettings* camera_settings = stream->getCameraSettings();
580 const openni::Status rc = camera_settings->setExposure(exposure);
581 if (rc != openni::STATUS_OK)
595 openni::CameraSettings* camera_seeting = stream->getCameraSettings();
597 ret = camera_seeting->getAutoExposureEnabled();
611 openni::CameraSettings* camera_seeting = stream->getCameraSettings();
613 ret = camera_seeting->getAutoWhiteBalanceEnabled();
627 openni::CameraSettings* camera_settings = stream->getCameraSettings();
629 ret = camera_settings->getExposure();
671 if (rc != openni::STATUS_OK)
687 if (rc != openni::STATUS_OK)
703 if (rc != openni::STATUS_OK)
713 stream <<
"Device info (" << device.
getUri() <<
")" << std::endl;
714 stream <<
" Vendor: " << device.
getVendor() << std::endl;
715 stream <<
" Name: " << device.
getName() << std::endl;
716 stream <<
" USB Vendor ID: " << device.
getUsbVendorId() << std::endl;
717 stream <<
" USB Product ID: " << device.
getUsbVendorId() << std::endl << std::endl;
721 stream <<
"IR sensor video modes:" << std::endl;
724 std::vector<OpenNI2VideoMode>::const_iterator it = video_modes.begin();
725 std::vector<OpenNI2VideoMode>::const_iterator it_end = video_modes.end();
726 for (; it != it_end; ++it)
727 stream <<
" - " << *it << std::endl;
731 stream <<
"No IR sensor available" << std::endl;
736 stream <<
"Color sensor video modes:" << std::endl;
739 std::vector<OpenNI2VideoMode>::const_iterator it = video_modes.begin();
740 std::vector<OpenNI2VideoMode>::const_iterator it_end = video_modes.end();
741 for (; it != it_end; ++it)
742 stream <<
" - " << *it << std::endl;
746 stream <<
"No Color sensor available" << std::endl;
751 stream <<
"Depth sensor video modes:" << std::endl;
754 std::vector<OpenNI2VideoMode>::const_iterator it = video_modes.begin();
755 std::vector<OpenNI2VideoMode>::const_iterator it_end = video_modes.end();
756 for (; it != it_end; ++it)
757 stream <<
" - " << *it << std::endl;
761 stream <<
"No Depth sensor available" << std::endl;
const std::string getUri() const
void setColorVideoMode(const OpenNI2VideoMode &video_mode)
bool hasDepthSensor() const
std::ostream & operator<<(std::ostream &stream, const OpenNI2Device &device)
boost::function< void(sensor_msgs::ImagePtr image)> FrameCallbackFunction
boost::shared_ptr< openni::VideoStream > depth_video_stream_
uint16_t getUsbVendorId() const
void setIRVideoMode(const OpenNI2VideoMode &video_mode)
boost::shared_ptr< openni::VideoStream > color_video_stream_
const OpenNI2VideoMode getDepthVideoMode()
void setAutoExposure(bool enable)
bool depth_video_started_
const OpenNI2VideoMode getIRVideoMode()
boost::shared_ptr< openni::VideoStream > getColorVideoStream() const
float getIRFocalLength(int output_y_resolution) const
std::vector< OpenNI2VideoMode > ir_video_modes_
float getColorFocalLength(int output_y_resolution) const
OpenNI2Device(const std::string &device_URI)
#define THROW_OPENNI_EXCEPTION(format,...)
bool hasColorSensor() const
const OpenNI2VideoMode getColorVideoMode()
bool color_video_started_
void setDepthVideoMode(const OpenNI2VideoMode &video_mode)
void setUseDeviceTimer(bool enable)
std::vector< OpenNI2VideoMode > color_video_modes_
bool isColorVideoModeSupported(const OpenNI2VideoMode &video_mode) const
bool isDepthVideoModeSupported(const OpenNI2VideoMode &video_mode) const
void setExposure(int exposure)
const std::string getVendor() const
void setDepthColorSync(bool enabled)
bool image_registration_activated_
float getBaseline() const
void setAutoWhiteBalance(bool enable)
const std::string getName() const
const std::string getStringID() const
boost::shared_ptr< OpenNI2FrameListener > ir_frame_listener
boost::shared_ptr< OpenNI2FrameListener > color_frame_listener
bool isDepthStreamStarted()
boost::shared_ptr< openni::VideoStream > getIRVideoStream() const
boost::shared_ptr< OpenNI2FrameListener > depth_frame_listener
boost::shared_ptr< openni::Device > openni_device_
const std::vector< OpenNI2VideoMode > & getSupportedColorVideoModes() const
boost::shared_ptr< openni::VideoStream > getDepthVideoStream() const
uint16_t getUsbProductId() const
bool isImageRegistrationModeSupported() const
bool isIRVideoModeSupported(const OpenNI2VideoMode &video_mode) const
boost::shared_ptr< openni::VideoStream > ir_video_stream_
boost::shared_ptr< openni::DeviceInfo > device_info_
bool getAutoWhiteBalance() const
void setImageRegistrationMode(bool enabled)
void setDepthFrameCallback(FrameCallbackFunction callback)
const OpenNI2DeviceInfo openni2_convert(const openni::DeviceInfo *pInfo)
const std::vector< OpenNI2VideoMode > & getSupportedIRVideoModes() const
void setColorFrameCallback(FrameCallbackFunction callback)
void setIRFrameCallback(FrameCallbackFunction callback)
bool isColorStreamStarted()
std::vector< OpenNI2VideoMode > depth_video_modes_
bool getAutoExposure() const
const std::vector< OpenNI2VideoMode > & getSupportedDepthVideoModes() const
float getDepthFocalLength(int output_y_resolution) const