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 #include <openni_camera/openni_device_primesense.h>
00038 #include <openni_camera/openni_image_yuv_422.h>
00039 #include <iostream>
00040 #include <sstream>
00041 #include <boost/thread/mutex.hpp>
00042
00043 using namespace boost;
00044
00045 namespace openni_wrapper
00046 {
00047
00048 DevicePrimesense::DevicePrimesense (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)
00049 : OpenNIDevice (context, device_node, image_node, depth_node, ir_node)
00050 {
00051
00052 enumAvailableModes ();
00053 setDepthOutputMode (getDefaultDepthMode ());
00054 setImageOutputMode (getDefaultImageMode ());
00055 setIROutputMode (getDefaultIRMode ());
00056
00057 unique_lock<mutex> image_lock(image_mutex_);
00058 XnStatus status = image_generator_.SetIntProperty ("InputFormat", 5);
00059 if (status != XN_STATUS_OK)
00060 THROW_OPENNI_EXCEPTION ("Error setting the image input format to Uncompressed 8-bit BAYER. Reason: %s", xnGetStatusString (status));
00061
00062 status = image_generator_.SetPixelFormat (XN_PIXEL_FORMAT_YUV422);
00063 if (status != XN_STATUS_OK)
00064 THROW_OPENNI_EXCEPTION ("Failed to set image pixel format to YUV422. Reason: %s", xnGetStatusString (status));
00065
00066 image_lock.unlock ();
00067
00068 lock_guard<mutex> depth_lock(depth_mutex_);
00069 status = depth_generator_.SetIntProperty ("RegistrationType", 1);
00070 if (status != XN_STATUS_OK)
00071 THROW_OPENNI_EXCEPTION ("Error setting the registration type. Reason: %s", xnGetStatusString (status));
00072 }
00073
00074 DevicePrimesense::~DevicePrimesense () throw ()
00075 {
00076 setDepthRegistration ( false );
00077 setSynchronization ( false );
00078
00079 depth_mutex_.lock ();
00080 depth_generator_.UnregisterFromNewDataAvailable (depth_callback_handle_);
00081 depth_mutex_.unlock ();
00082
00083 image_mutex_.lock ();
00084 image_generator_.UnregisterFromNewDataAvailable (image_callback_handle_);
00085 image_mutex_.unlock ();
00086 }
00087
00088 bool DevicePrimesense::isImageResizeSupported (unsigned input_width, unsigned input_height, unsigned output_width, unsigned output_height) const throw ()
00089 {
00090 return ImageYUV422::resizingSupported (input_width, input_height, output_width, output_height);
00091 }
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 void DevicePrimesense::enumAvailableModes () throw (OpenNIException)
00135 {
00136 XnMapOutputMode output_mode;
00137 available_image_modes_.clear();
00138 available_depth_modes_.clear();
00139
00140
00141 output_mode.nFPS = 30;
00142 output_mode.nXRes = XN_VGA_X_RES;
00143 output_mode.nYRes = XN_VGA_Y_RES;
00144 available_depth_modes_.push_back (output_mode);
00145
00146 output_mode.nFPS = 25;
00147 output_mode.nXRes = XN_VGA_X_RES;
00148 output_mode.nYRes = XN_VGA_Y_RES;
00149 available_depth_modes_.push_back (output_mode);
00150
00151 output_mode.nFPS = 25;
00152 output_mode.nXRes = XN_QVGA_X_RES;
00153 output_mode.nYRes = XN_QVGA_Y_RES;
00154 available_depth_modes_.push_back (output_mode);
00155
00156 output_mode.nFPS = 30;
00157 output_mode.nXRes = XN_QVGA_X_RES;
00158 output_mode.nYRes = XN_QVGA_Y_RES;
00159 available_depth_modes_.push_back (output_mode);
00160
00161 output_mode.nFPS = 60;
00162 output_mode.nXRes = XN_QVGA_X_RES;
00163 output_mode.nYRes = XN_QVGA_Y_RES;
00164 available_depth_modes_.push_back (output_mode);
00165
00166
00167 output_mode.nFPS = 30;
00168 output_mode.nXRes = XN_VGA_X_RES;
00169 output_mode.nYRes = XN_VGA_Y_RES;
00170 available_image_modes_.push_back (output_mode);
00171
00172 output_mode.nFPS = 25;
00173 output_mode.nXRes = XN_VGA_X_RES;
00174 output_mode.nYRes = XN_VGA_Y_RES;
00175 available_image_modes_.push_back (output_mode);
00176
00177
00178
00179
00180
00181
00182 output_mode.nFPS = 25;
00183 output_mode.nXRes = XN_QVGA_X_RES;
00184 output_mode.nYRes = XN_QVGA_Y_RES;
00185 available_image_modes_.push_back (output_mode);
00186
00187 output_mode.nFPS = 30;
00188 output_mode.nXRes = XN_QVGA_X_RES;
00189 output_mode.nYRes = XN_QVGA_Y_RES;
00190 available_image_modes_.push_back (output_mode);
00191
00192 output_mode.nFPS = 60;
00193 output_mode.nXRes = XN_QVGA_X_RES;
00194 output_mode.nYRes = XN_QVGA_Y_RES;
00195 available_image_modes_.push_back (output_mode);
00196 }
00197
00198 boost::shared_ptr<Image> DevicePrimesense::getCurrentImage (boost::shared_ptr<xn::ImageMetaData> image_data) const throw ()
00199 {
00200 return boost::shared_ptr<Image> ( new ImageYUV422 (image_data) );
00201 }
00202
00203 void DevicePrimesense::startImageStream () throw (OpenNIException)
00204 {
00205
00206
00207
00208 if (isDepthStreamRunning ())
00209 {
00210 if (isDepthRegistered ())
00211 {
00212
00213 setDepthRegistration (false);
00214
00215
00216 setDepthRegistration (true);
00217
00218
00219 setDepthRegistration (false);
00220
00221
00222 OpenNIDevice::startImageStream ();
00223
00224
00225 setDepthRegistration (true);
00226 }
00227 else
00228 {
00229
00230 setDepthRegistration (true);
00231
00232 setDepthRegistration (false);
00233
00234
00235 OpenNIDevice::startImageStream ();
00236 }
00237 }
00238 else
00239
00240 OpenNIDevice::startImageStream ();
00241 }
00242
00243 void DevicePrimesense::startDepthStream () throw (OpenNIException)
00244 {
00245 if (isDepthRegistered ())
00246 {
00247
00248 setDepthRegistration (false);
00249
00250
00251 OpenNIDevice::startDepthStream ();
00252
00253
00254 setDepthRegistration (true);
00255 }
00256 else
00257
00258 OpenNIDevice::startDepthStream ();
00259 }
00260
00261 }