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 std;
00044 using namespace boost;
00045
00046 namespace openni_wrapper
00047 {
00048
00049 DevicePrimesense::DevicePrimesense (xn::Context& context, const xn::NodeInfo& device_node, const xn::NodeInfo& image_node, const xn::NodeInfo& depth_node) throw (OpenNIException)
00050 : OpenNIDevice (context, device_node, image_node, depth_node)
00051 {
00052 Init ();
00053
00054 unique_lock<mutex> image_lock(image_mutex_);
00055 XnStatus status = image_generator_.SetIntProperty ("InputFormat", 5);
00056 if (status != XN_STATUS_OK)
00057 THROW_OPENNI_EXCEPTION ("Error setting the image input format to Uncompressed 8-bit BAYER. Reason: %s", xnGetStatusString (status));
00058
00059 status = image_generator_.SetPixelFormat (XN_PIXEL_FORMAT_YUV422);
00060 if (status != XN_STATUS_OK)
00061 THROW_OPENNI_EXCEPTION ("Failed to set image pixel format to YUV422. Reason: %s", xnGetStatusString (status));
00062
00063 image_lock.unlock ();
00064
00065 lock_guard<mutex> depth_lock(depth_mutex_);
00066 status = depth_generator_.SetIntProperty ("RegistrationType", 1);
00067 if (status != XN_STATUS_OK)
00068 THROW_OPENNI_EXCEPTION ("Error setting the registration type. Reason: %s", xnGetStatusString (status));
00069 }
00070
00071 DevicePrimesense::~DevicePrimesense () throw ()
00072 {
00073 setDepthRegistration ( false );
00074 setSynchronization ( false );
00075
00076 depth_mutex_.lock ();
00077 depth_generator_.UnregisterFromNewDataAvailable (depth_callback_handle_);
00078 depth_mutex_.unlock ();
00079
00080 image_mutex_.lock ();
00081 image_generator_.UnregisterFromNewDataAvailable (image_callback_handle_);
00082 image_mutex_.unlock ();
00083 }
00084
00085 bool DevicePrimesense::isImageResizeSupported (unsigned input_width, unsigned input_height, unsigned output_width, unsigned output_height) const throw ()
00086 {
00087 return ImageYUV422::resizingSupported (input_width, input_height, output_width, output_height);
00088 }
00089
00090
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 void DevicePrimesense::getAvailableModes () throw (OpenNIException)
00132 {
00133 XnMapOutputMode output_mode;
00134 available_image_modes_.clear();
00135 available_depth_modes_.clear();
00136
00137
00138 output_mode.nFPS = 30;
00139 output_mode.nXRes = XN_VGA_X_RES;
00140 output_mode.nYRes = XN_VGA_Y_RES;
00141 available_depth_modes_.push_back (output_mode);
00142
00143 output_mode.nFPS = 25;
00144 output_mode.nXRes = XN_VGA_X_RES;
00145 output_mode.nYRes = XN_VGA_Y_RES;
00146 available_depth_modes_.push_back (output_mode);
00147
00148 output_mode.nFPS = 25;
00149 output_mode.nXRes = XN_QVGA_X_RES;
00150 output_mode.nYRes = XN_QVGA_Y_RES;
00151 available_depth_modes_.push_back (output_mode);
00152
00153 output_mode.nFPS = 30;
00154 output_mode.nXRes = XN_QVGA_X_RES;
00155 output_mode.nYRes = XN_QVGA_Y_RES;
00156 available_depth_modes_.push_back (output_mode);
00157
00158 output_mode.nFPS = 60;
00159 output_mode.nXRes = XN_QVGA_X_RES;
00160 output_mode.nYRes = XN_QVGA_Y_RES;
00161 available_depth_modes_.push_back (output_mode);
00162
00163
00164 output_mode.nFPS = 30;
00165 output_mode.nXRes = XN_VGA_X_RES;
00166 output_mode.nYRes = XN_VGA_Y_RES;
00167 available_image_modes_.push_back (output_mode);
00168
00169 output_mode.nFPS = 25;
00170 output_mode.nXRes = XN_VGA_X_RES;
00171 output_mode.nYRes = XN_VGA_Y_RES;
00172 available_image_modes_.push_back (output_mode);
00173
00174
00175
00176
00177
00178
00179 output_mode.nFPS = 25;
00180 output_mode.nXRes = XN_QVGA_X_RES;
00181 output_mode.nYRes = XN_QVGA_Y_RES;
00182 available_image_modes_.push_back (output_mode);
00183
00184 output_mode.nFPS = 30;
00185 output_mode.nXRes = XN_QVGA_X_RES;
00186 output_mode.nYRes = XN_QVGA_Y_RES;
00187 available_image_modes_.push_back (output_mode);
00188
00189 output_mode.nFPS = 60;
00190 output_mode.nXRes = XN_QVGA_X_RES;
00191 output_mode.nYRes = XN_QVGA_Y_RES;
00192 available_image_modes_.push_back (output_mode);
00193 }
00194
00195 boost::shared_ptr<Image> DevicePrimesense::getCurrentImage (boost::shared_ptr<xn::ImageMetaData> image_data) const throw ()
00196 {
00197 return boost::shared_ptr<Image> ( new ImageYUV422 (image_data) );
00198 }
00199
00200 void DevicePrimesense::startImageStream () throw (OpenNIException)
00201 {
00202
00203
00204
00205 if (isDepthStreamRunning ())
00206 {
00207 if (isDepthRegistered ())
00208 {
00209
00210 setDepthRegistration (false);
00211
00212
00213 setDepthRegistration (true);
00214
00215
00216 setDepthRegistration (false);
00217
00218
00219 OpenNIDevice::startImageStream ();
00220
00221
00222 setDepthRegistration (true);
00223 }
00224 else
00225 {
00226
00227 setDepthRegistration (true);
00228
00229 setDepthRegistration (false);
00230
00231
00232 OpenNIDevice::startImageStream ();
00233 }
00234 }
00235 else
00236
00237 OpenNIDevice::startImageStream ();
00238 }
00239
00240 void DevicePrimesense::startDepthStream () throw (OpenNIException)
00241 {
00242 if (isDepthRegistered ())
00243 {
00244
00245 setDepthRegistration (false);
00246
00247
00248 OpenNIDevice::startDepthStream ();
00249
00250
00251 setDepthRegistration (true);
00252 }
00253 else
00254
00255 OpenNIDevice::startDepthStream ();
00256 }
00257
00258 }