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 #include <openni_camera/openni_device_kinect.h>
00038 #include <openni_camera/openni_image_bayer_grbg.h>
00039 #include <iostream>
00040 #include <sstream>
00041 #include <boost/thread/mutex.hpp>
00042
00043 using namespace std;
00044 using namespace boost;
00045
00046 namespace openni_wrapper
00047 {
00048
00049 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) throw (OpenNIException)
00050 : OpenNIDevice (context, device_node, image_node, depth_node, ir_node)
00051 , debayering_method_ (ImageBayerGRBG::EdgeAwareWeighted)
00052 {
00053
00054 Init ();
00055
00056
00057 XnStatus status;
00058
00059 unique_lock<mutex> image_lock(image_mutex_);
00060
00061 status = image_generator_.SetIntProperty ("InputFormat", 6);
00062 if (status != XN_STATUS_OK)
00063 THROW_OPENNI_EXCEPTION ("Error setting the image input format to Uncompressed 8-bit BAYER. Reason: %s", xnGetStatusString (status));
00064
00065
00066 status = image_generator_.SetPixelFormat (XN_PIXEL_FORMAT_GRAYSCALE_8_BIT);
00067 if (status != XN_STATUS_OK)
00068 THROW_OPENNI_EXCEPTION ("Failed to set image pixel format to 8bit-grayscale. Reason: %s", xnGetStatusString (status));
00069 image_lock.unlock ();
00070
00071 lock_guard<mutex> depth_lock(depth_mutex_);
00072
00073 status = depth_generator_.SetIntProperty ("RegistrationType", 2);
00074 if (status != XN_STATUS_OK)
00075 THROW_OPENNI_EXCEPTION ("Error setting the registration type. Reason: %s", xnGetStatusString (status));
00076 }
00077
00078 DeviceKinect::~DeviceKinect () throw ()
00079 {
00080 depth_mutex_.lock ();
00081 depth_generator_.UnregisterFromNewDataAvailable (depth_callback_handle_);
00082 depth_mutex_.unlock ();
00083
00084 image_mutex_.lock ();
00085 image_generator_.UnregisterFromNewDataAvailable (image_callback_handle_);
00086 image_mutex_.unlock ();
00087 }
00088
00089 bool DeviceKinect::isImageResizeSupported (unsigned input_width, unsigned input_height, unsigned output_width, unsigned output_height) const throw ()
00090 {
00091 return ImageBayerGRBG::resizingSupported (input_width, input_height, output_width, output_height);
00092 }
00093
00094 void DeviceKinect::getAvailableModes () throw (OpenNIException)
00095 {
00096 XnMapOutputMode output_mode;
00097 available_image_modes_.clear();
00098 available_depth_modes_.clear();
00099
00100 output_mode.nFPS = 30;
00101 output_mode.nXRes = XN_VGA_X_RES;
00102 output_mode.nYRes = XN_VGA_Y_RES;
00103 available_image_modes_.push_back (output_mode);
00104 available_depth_modes_.push_back (output_mode);
00105
00106 output_mode.nFPS = 15;
00107 output_mode.nXRes = XN_SXGA_X_RES;
00108 output_mode.nYRes = XN_SXGA_Y_RES;
00109 available_image_modes_.push_back (output_mode);
00110 }
00111
00112 boost::shared_ptr<Image> DeviceKinect::getCurrentImage (boost::shared_ptr<xn::ImageMetaData> image_data) const throw ()
00113 {
00114 return boost::shared_ptr<Image> (new ImageBayerGRBG (image_data, debayering_method_));
00115 }
00116
00117 void DeviceKinect::setSynchronization (bool on_off) throw (OpenNIException)
00118 {
00119 if (on_off)
00120 THROW_OPENNI_EXCEPTION ("Microsoft Kinect does not support Hardware synchronization.");
00121 }
00122
00123 bool DeviceKinect::isSynchronized () const throw (OpenNIException)
00124 {
00125 return false;
00126 }
00127
00128 bool DeviceKinect::isSynchronizationSupported () const throw ()
00129 {
00130 return false;
00131 }
00132
00133 bool DeviceKinect::isDepthCropped () const throw (OpenNIException)
00134 {
00135 return false;
00136 }
00137
00138 void DeviceKinect::setDepthCropping (unsigned x, unsigned y, unsigned width, unsigned height) throw (OpenNIException)
00139 {
00140 if (width != 0 && height != 0)
00141 THROW_OPENNI_EXCEPTION ("Microsoft Kinect does not support cropping for the depth stream.");
00142 }
00143
00144 bool DeviceKinect::isDepthCroppingSupported () const throw ()
00145 {
00146 return false;
00147 }
00148
00149 }