Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <pcl/pcl_config.h>
00039 #ifdef HAVE_OPENNI
00040
00041 #ifdef __GNUC__
00042 #pragma GCC diagnostic ignored "-Wold-style-cast"
00043 #endif
00044
00045 #include <pcl/io/openni_camera/openni_device_kinect.h>
00046 #include <pcl/io/openni_camera/openni_image_bayer_grbg.h>
00047
00048 namespace openni_wrapper
00049 {
00050
00052 bool
00053 openni_wrapper::DeviceKinect::isSynchronizationSupported () const throw ()
00054 {
00055 return (false);
00056 }
00057
00059 openni_wrapper::DeviceKinect::DeviceKinect (xn::Context& context, const xn::NodeInfo& device_node, const xn::NodeInfo& image_node, const xn::NodeInfo& depth_node, const xn::NodeInfo& ir_node)
00060 : OpenNIDevice (context, device_node, image_node, depth_node, ir_node)
00061 , debayering_method_ (ImageBayerGRBG::EdgeAwareWeighted)
00062 {
00063
00064 enumAvailableModes ();
00065 setDepthOutputMode (getDefaultDepthMode ());
00066 setImageOutputMode (getDefaultImageMode ());
00067 setIROutputMode (getDefaultIRMode ());
00068
00069
00070 XnStatus status;
00071
00072 boost::unique_lock<boost::mutex> image_lock (image_mutex_);
00073
00074 status = image_generator_.SetIntProperty ("InputFormat", 6);
00075 if (status != XN_STATUS_OK)
00076 THROW_OPENNI_EXCEPTION ("Error setting the image input format to Uncompressed 8-bit BAYER. Reason: %s", xnGetStatusString (status));
00077
00078
00079 status = image_generator_.SetPixelFormat (XN_PIXEL_FORMAT_GRAYSCALE_8_BIT);
00080 if (status != XN_STATUS_OK)
00081 THROW_OPENNI_EXCEPTION ("Failed to set image pixel format to 8bit-grayscale. Reason: %s", xnGetStatusString (status));
00082 image_lock.unlock ();
00083
00084 boost::lock_guard<boost::mutex> depth_lock (depth_mutex_);
00085
00086 status = depth_generator_.SetIntProperty ("RegistrationType", 2);
00087 if (status != XN_STATUS_OK)
00088 THROW_OPENNI_EXCEPTION ("Error setting the registration type. Reason: %s", xnGetStatusString (status));
00089 }
00090
00092 openni_wrapper::DeviceKinect::~DeviceKinect () throw ()
00093 {
00094 depth_mutex_.lock ();
00095 depth_generator_.UnregisterFromNewDataAvailable (depth_callback_handle_);
00096 depth_mutex_.unlock ();
00097
00098 image_mutex_.lock ();
00099 image_generator_.UnregisterFromNewDataAvailable (image_callback_handle_);
00100 image_mutex_.unlock ();
00101 }
00102
00104 bool
00105 openni_wrapper::DeviceKinect::isImageResizeSupported (unsigned input_width, unsigned input_height, unsigned output_width, unsigned output_height) const throw ()
00106 {
00107 return (ImageBayerGRBG::resizingSupported (input_width, input_height, output_width, output_height));
00108 }
00109
00111 void
00112 openni_wrapper::DeviceKinect::enumAvailableModes () throw ()
00113 {
00114 XnMapOutputMode output_mode;
00115 available_image_modes_.clear();
00116 available_depth_modes_.clear();
00117
00118 output_mode.nFPS = 30;
00119 output_mode.nXRes = XN_VGA_X_RES;
00120 output_mode.nYRes = XN_VGA_Y_RES;
00121 available_image_modes_.push_back (output_mode);
00122 available_depth_modes_.push_back (output_mode);
00123
00124 output_mode.nFPS = 15;
00125 output_mode.nXRes = XN_SXGA_X_RES;
00126 output_mode.nYRes = XN_SXGA_Y_RES;
00127 available_image_modes_.push_back (output_mode);
00128 }
00129
00131 boost::shared_ptr<openni_wrapper::Image>
00132 openni_wrapper::DeviceKinect::getCurrentImage (boost::shared_ptr<xn::ImageMetaData> image_data) const throw ()
00133 {
00134 return (boost::shared_ptr<Image> (new ImageBayerGRBG (image_data, debayering_method_)));
00135 }
00136
00137 }
00138 #endif