13COpenNi2Device::COpenNi2Device(
void)
33 m_has_image_data =
TRUE;
34 m_has_depth_data =
TRUE;
38 imageMode.setFps(m_nfps);
39 imageMode.setResolution(m_xsize, m_ysize);
40 imageMode.setPixelFormat(openni::PIXEL_FORMAT_RGB888);
42 depthMode.setFps(m_nfps);
43 depthMode.setResolution(m_xsize, m_ysize);
44 depthMode.setPixelFormat(openni::PIXEL_FORMAT_DEPTH_1_MM);
48BOOL COpenNi2Device::init(BOOL use_image)
52 for (
int s=0; s<OPENNI2_STREAM_DATA_NUM; s++) m_streams[s] = NULL;
56 BOOL ret = create_Context();
57 if (ret && use_image) ret = create_Image();
58 if (ret) ret = create_Depth();
60 const openni::DeviceInfo info = context->getDeviceInfo();
61 DEBUG_INFO(
"INFO: COpenNi2Device::init(): Device Name = %s", info.getName());
71BOOL COpenNi2Device::init(
char* fname, BOOL use_image)
76 copy_s2Buffer(
"ERROR: COpenNi2Device::init(): File name is NULL.", &m_err_mesg);
82 for (
int s=0; s<OPENNI2_STREAM_DATA_NUM; s++) m_streams[s] = NULL;
84 BOOL ret = create_Context(fname);
85 if (ret && use_image) ret = create_Image();
86 if (ret) ret = create_Depth();
93void COpenNi2Device::free(
void)
95 DEBUG_LOG(
"LOG: COpenNi2Device::free(): deleting Recorder ...");
98 DEBUG_LOG(
"LOG: COpenNi2Device::free(): deleting Image ...");
100 DEBUG_LOG(
"LOG: COpenNi2Device::free(): deleting Depth ...");
102 DEBUG_LOG(
"LOG: COpenNi2Device::free(): deleting Context ...");
104 DEBUG_LOG(
"LOG: COpenNi2Device::free(): deleted Generators.");
108 DEBUG_LOG(
"LOG: COpenNi2Device::free(): END");
116BOOL COpenNi2Device::create_Context(
char* fname)
119 context =
new openni::Device();
121 DEBUG_ERR(
"ERROR: COpenNi2Device::create_Context(): context is NULL!!");
125 else context->close();
127 const char* uri = fname;
128 if (uri==NULL) uri = openni::ANY_DEVICE;
130 openni::Status ret = context->open(uri);
131 if (ret!=openni::STATUS_OK) {
132 DEBUG_ERR(
"ERROR: COpenNi2Device::create_Context(): Device Open Error!! (%d)", ret);
139 DEBUG_INFO(
"INFO: COpenNi2Device::create_Context(): created Context.");
144BOOL COpenNi2Device::create_Recorder(
char* fname, BOOL use_image)
147 copy_s2Buffer(
"ERROR: COpenNi2Device::create_Recorder(): File name is NULL.", &m_err_mesg);
150 if (depth==NULL || (use_image && image==NULL)) {
151 copy_s2Buffer(
"ERROR: COpenNi2Device::create_Recorder(): Image or Depth Stream is NULL.", &m_err_mesg);
155 if (recorder==NULL) {
156 recorder =
new openni::Recorder();
157 if (recorder==NULL) {
158 DEBUG_ERR(
"ERROR: COpenNi2Device::create_Recorder(): recorder is NULL!!");
162 else recorder->stop();
164 openni::Status ret = recorder->create(fname);
165 if (ret!=openni::STATUS_OK) {
167 DEBUG_ERR(
"ERROR: COpenNi2Device::create_Recorder: File Open Error.");
168 copy_s2Buffer(
"ERROR: COpenNi2Device::create_Recorder: File Open Error.", &m_err_mesg);
172 ret = recorder->attach(*depth,
true);
173 if (ret==openni::STATUS_OK && use_image) ret = recorder->attach(*image,
true);
174 if (ret!=openni::STATUS_OK) {
176 DEBUG_ERR(
"ERROR: COpenNi2Device::create_Recorder: Stream Attach Error.");
177 copy_s2Buffer(
"ERROR: COpenNi2Device::create_Recorder: Stream Attach Error.", &m_err_mesg);
181 DEBUG_INFO(
"INFO: COpenNi2Device::create_Recorder(): created Recorder.");
186BOOL COpenNi2Device::create_Image(
void)
188 if (!m_has_camera)
return FALSE;
191 copy_s2Buffer(
"ERROR: COpenNi2Device::create_Image(): context is NULL.", &m_err_mesg);
195 image =
new openni::VideoStream();
196 if (image==NULL)
return FALSE;
198 openni::Status ret = image->create(*context, openni::SENSOR_COLOR);
199 if (ret!=openni::STATUS_OK) {
201 copy_s2Buffer(
"ERROR: COpenNi2Device::create_Image(): Craete Error.", &m_err_mesg);
205 ret = image->start();
206 if (ret!=openni::STATUS_OK) {
208 copy_s2Buffer(
"ERROR: COpenNi2Device::create_Image(): Start Error.", &m_err_mesg);
212 image->setVideoMode(imageMode);
214 m_streams[OPENNI2_IMAGE_INDEX] = image;
215 m_stream_flg |= OPENNI2_IMAGE_FLAG;
218 DEBUG_INFO(
"INFO: COpenNi2Device::create_Image(): created Image Stream.");
223BOOL COpenNi2Device::create_Depth(
void)
226 copy_s2Buffer(
"ERROR: COpenNi2Device::create_Depth(): context is NULL.", &m_err_mesg);
230 depth =
new openni::VideoStream();
231 if (depth==NULL)
return FALSE;
233 openni::Status ret = depth->create(*context, openni::SENSOR_DEPTH);
234 if (ret!=openni::STATUS_OK) {
236 copy_s2Buffer(
"ERROR: COpenNi2Device::create_Depth(): Craete Error.", &m_err_mesg);
240 ret = depth->start();
241 if (ret!=openni::STATUS_OK) {
243 copy_s2Buffer(
"ERROR: COpenNi2Device::create_Depth(): Start Error.", &m_err_mesg);
247 depth->setVideoMode(depthMode);
249 m_streams[OPENNI2_DEPTH_INDEX] = depth;
250 m_stream_flg |= OPENNI2_DEPTH_FLAG;
253 DEBUG_INFO(
"INFO: COpenNi2Device::create_Depth(): created Depth Stream.");
258BOOL COpenNi2Device::create_User(
void)
260 user =
new nite::UserTracker();
261 if (user==NULL)
return FALSE;
263 nite::Status ret = user->create(context);
264 if (ret!=nite::STATUS_OK) {
266 copy_s2Buffer(
"ERROR: COpenNi2Device::create_Depth(): Create Error", &m_err_mesg);
270 DEBUG_INFO(
"INFO: COpenNi2Device::create_User(): created User Tracker.");
279void COpenNi2Device::delete_Context(
void)
281 if (context==NULL || !context->isValid())
return;
291void COpenNi2Device::delete_Recorder(
void)
293 if (recorder==NULL || !recorder->isValid())
return;
295 int prev_state = m_state;
299 DEBUG_INFO(
"INFO: COpenNi2Device::delete_Recorder(): Recorder Stopped.");
303 m_state = prev_state;
309void COpenNi2Device::delete_Image(
void)
312 m_streams[OPENNI2_IMAGE_INDEX] = NULL;
313 m_stream_flg &= ~OPENNI2_IMAGE_FLAG;
315 if (image==NULL || !image->isValid())
return;
320 if (imageFrame.isValid()) imageFrame.release();
327void COpenNi2Device::delete_Depth(
void)
330 m_streams[OPENNI2_DEPTH_INDEX] = NULL;
331 m_stream_flg &= ~OPENNI2_DEPTH_FLAG;
333 if (depth==NULL || !depth->isValid())
return;
338 if (depthFrame.isValid()) depthFrame.release();
345void COpenNi2Device::delete_User(
void)
347 if (user==NULL || !user->isValid())
return;
350 if (userFrame.isValid()) userFrame.release();
362BOOL COpenNi2Device::start_Recorde(
char* file_name, BOOL use_image)
364 DEBUG_INFO(
"INFO: COpenNi2Device::delete_Recorder(): Recorder Starting ...");
369 int prev_state = m_state;
373 ret = create_Recorder(file_name, use_image);
375 openni::Status nc = recorder->start();
376 if (nc!=openni::STATUS_OK) {
377 copy_s2Buffer(
"ERROR: COpenNi2Device::start_Recorde: Start Error.", &m_err_mesg);
382 m_state = prev_state;
385 DEBUG_INFO(
"INFO: COpenNi2Device::delete_Recorder(): Recorder Started.");
390 DEBUG_INFO(
"INFO: COpenNi2Device::delete_Recorder(): Recorder can not Start.");
397void COpenNi2Device::stop_Recorde(
void)
399 DEBUG_INFO(
"INFO: COpenNi2Device::delete_Recorder(): Recorder Stopping ...");
400 if (recorder!=NULL && recorder->isValid()) {
410BOOL COpenNi2Device::setup_Tracking(
int profile,
double smooth)
413 nite::Status nc = user->setSkeletonSmoothingFactor(smooth);
414 if (nc==nite::STATUS_OK)
return TRUE;
425void COpenNi2Device::wait_StreamData(
void)
430 unsigned char flag = 0x00;
433 m_has_image_data =
FALSE;
434 m_has_depth_data =
FALSE;
438 rc = openni::OpenNI::waitForAnyStream(m_streams, m_stream_num, &stream_idx, 0);
439 if (rc==openni::STATUS_OK) {
440 if (stream_idx==OPENNI2_IMAGE_INDEX) {
442 image->readFrame(&imageFrame);
443 flag |= OPENNI2_IMAGE_FLAG;
444 m_has_image_data =
TRUE;
447 else if (stream_idx==OPENNI2_DEPTH_INDEX) {
449 depth->readFrame(&depthFrame);
450 flag |= OPENNI2_DEPTH_FLAG;
451 m_has_depth_data =
TRUE;
463 if ((flag & m_stream_flg)==m_stream_flg)
break;
469BOOL COpenNi2Device::set_ImageData(
void)
473 if (imageFrame.isValid())
return TRUE;
479BOOL COpenNi2Device::set_DepthData(
void)
483 if (depthFrame.isValid())
return TRUE;
489BOOL COpenNi2Device::set_SceneData(
void)
492 user->readFrame(&userFrame);
493 if (userFrame.isValid())
return TRUE;
507Buffer jbxl::initialize_OpenNI2(
void)
511 openni::Status rc = openni::OpenNI::initialize();
512 if (rc!=openni::STATUS_OK) {
514 copy_s2Buffer(
"ERROR: jbxl::initializeOpenNI2(): Initialize OpenNI Error!!\n", &mesg);
515 cat_s2Buffer (openni::OpenNI::getExtendedError(), &mesg);
518 else DEBUG_INFO(
"INFO: jbxl::initialize_OpenNI2(): initialize OpenNI2");
524void jbxl::shutdown_OpenNI2(
void)
526 openni::OpenNI::shutdown();
527 DEBUG_INFO(
"INFO: jbxl::shutdown_OpenNI2(): shutdown OpenNI2");
532Buffer jbxl::initialize_NiTE2(
void)
536 nite::Status nc = nite::NiTE::initialize();
537 if (nc!=nite::STATUS_OK) {
539 copy_s2Buffer(
"ERROR: jbxl::initializeNiTE2(): Initialize NiTE Error!!\n", &mesg);
542 else DEBUG_INFO(
"INFO: jbxl::initialize_NiTE2(): initialize NiTE2");
548void jbxl::shutdown_NiTE2(
void)
550 nite::NiTE::shutdown();
551 DEBUG_INFO(
"INFO: jbxl::shutdown_NiTE2(): shutdown NiTE2");
#define NI_STATE_SAVE_WORKING
#define NI_WORKING_WAIT_TIME
#define OPENNI_DEPTH_YSIZE
#define NI_STATE_DETECT_STOPPED
#define OPENNI_DEPTH_XSIZE
Buffer make_Buffer(int sz)
Buffer型変数のバッファ部をつくり出す.
void free_Buffer(Buffer *buf)
Buffer型変数のバッファ部を解放する
Buffer init_Buffer()
初期化したBuffer型変数を返す.
#define copy_s2Buffer(src, dst)
copy_b2Buffer()
#define cat_s2Buffer(src, dst)
cat_b2Buffer()
unsigned char * buf
バッファの先頭へのポインタ.str[bufsz]は必ず 0x00となる.