00001
00002 #include "WinBaseLib.h"
00003 #include "KinectDevice.h"
00004 #include "NiDevice.h"
00005
00006
00007 #ifdef ENABLE_KINECT_SDK
00008
00009 using namespace jbxl;
00010 using namespace jbxwl;
00011
00012
00014
00015
00016 CKinectDevice::CKinectDevice(void)
00017 {
00018 context = NULL;
00019
00020 image = NULL;
00021 depth = NULL;
00022 skeleton = NULL;
00023 face = NULL;
00024
00025 smoothParam = NULL;
00026
00027 m_count = 0;
00028 m_state = NI_STATE_DETECT_STOPPED;
00029 m_err_mesg = _T("");
00030
00031 m_xsize = 0;
00032 m_ysize = 0;
00033 m_nfps = 0;
00034
00035 clear_JointsData();
00036 }
00037
00038
00039
00040 CKinectDevice::~CKinectDevice(void)
00041 {
00042 DEBUG_INFO("DESTRUCTOR: CKinectDevice: START\n");
00043 free();
00044 DEBUG_INFO("DESTRUCTOR: CKinectDevice: END\n");
00045 }
00046
00047
00048
00049 BOOL CKinectDevice::init(DWORD mode, BOOL use_image)
00050 {
00051
00052 HRESULT hrt = ::NuiGetSensorCount(&m_count);
00053 if (FAILED(hrt) || m_count<=0) {
00054 m_err_mesg = _T("CKinectDevice::init(): WARNING: No Kinect is detected.\n");
00055 return FALSE;
00056 }
00057
00058 BOOL ret = create_Context(mode);
00059 if (ret && use_image) create_Image();
00060 if (ret) ret = create_Depth();
00061
00062 if (ret) {
00063 if (image!=NULL) {
00064 m_xsize = image->m_xsize;
00065 m_ysize = image->m_ysize;
00066 m_nfps = image->m_nfps;
00067 }
00068 else if (depth!=NULL) {
00069 m_xsize = depth->m_xsize;
00070 m_ysize = depth->m_ysize;
00071 m_nfps = depth->m_nfps;
00072 }
00073 else {
00074 m_err_mesg = _T("CKinectDevice::init(): ERROR: Unknown Error is occurred!!");
00075 ret = FALSE;
00076 }
00077 }
00078
00079 return ret;
00080 }
00081
00082
00083
00084 void CKinectDevice::free(void)
00085 {
00086 delete_Face();
00087 delete_Depth();
00088 delete_Image();
00089 delete_Context();
00090
00091
00092 }
00093
00094
00095
00096 void CKinectDevice::clear_JointsData(void)
00097 {
00098 memset(jointPosData, 0, sizeof(Vector4)*KINECT_JOINT_NUM);
00099 }
00100
00101
00102
00103
00105
00106
00107 BOOL CKinectDevice::create_Context(DWORD mode, int index)
00108 {
00109 HRESULT hrt = NuiCreateSensorByIndex(index, &context);
00110 if (FAILED(hrt)) {
00111 m_err_mesg = _T("CKinectDevice::create_Context(): ERROR: Fail to create Device.");
00112 return FALSE;
00113 }
00114
00115 hrt = context->NuiInitialize(mode);
00116 if (FAILED(hrt)) {
00117 delete_Context();
00118 m_err_mesg = _T("CKinectDevice::create_Context(): ERROR: Fail to initalize Device.");
00119 return FALSE;
00120 }
00121
00122 return TRUE;
00123 }
00124
00125
00126
00127 BOOL CKinectDevice::create_Image(void)
00128 {
00129 NUI_IMAGE_RESOLUTION reso = NUI_IMAGE_RESOLUTION_640x480;
00130
00131
00132 if (context==NULL) {
00133 m_err_mesg = _T("CKinectDevice::create_Image(): ERROR: context is NULL.");
00134 return FALSE;
00135 }
00136 if (image==NULL) image = new CKinectImage();
00137
00138
00139 HANDLE hdl = image->create(TRUE, FALSE, NULL);
00140 if (hdl==NULL) {
00141 delete_Image();
00142 m_err_mesg = _T("CKinectDevice::create_Image(): ERROR: Fail to create Image.");
00143 return FALSE;
00144 }
00145
00146 HRESULT hrt = context->NuiImageStreamOpen(NUI_IMAGE_TYPE_COLOR, reso, NULL, 2, image->m_handle, &image->m_stream);
00147 if (FAILED(hrt)) {
00148 delete_Image();
00149 m_err_mesg = _T("CKinectDevice::create_Image(): ERROR: Fail to open stream of Image.");
00150 return FALSE;
00151 }
00152
00153 NuiImageResolutionToSize(reso, (DWORD&)image->m_xsize, (DWORD&)image->m_ysize);
00154 image->m_nfps = 30;
00155
00156 if (image->m_data==NULL) image->make_data();
00157
00158 return TRUE;
00159 }
00160
00161
00162
00163 BOOL CKinectDevice::create_Depth(void)
00164 {
00165 NUI_IMAGE_RESOLUTION reso = NUI_IMAGE_RESOLUTION_640x480;
00166
00167
00168 if (context==NULL) {
00169 m_err_mesg = _T("CKinectDevice::create_Depth(): ERROR: context is NULL.");
00170 return FALSE;
00171 }
00172 if (depth==NULL) depth = new CKinectDepth();
00173
00174
00175 HANDLE hdl = depth->create(TRUE, FALSE, NULL);
00176 if (hdl==NULL) {
00177 delete_Depth();
00178 m_err_mesg = _T("CKinectDevice::create_Depth(): ERROR: Fail to create Depth.");
00179 return FALSE;
00180 }
00181
00182 HRESULT hrt = context->NuiImageStreamOpen(NUI_IMAGE_TYPE_DEPTH_AND_PLAYER_INDEX, reso, NULL, 2, depth->m_handle, &depth->m_stream);
00183 if (FAILED(hrt)) {
00184 delete_Depth();
00185 m_err_mesg = _T("CKinectDevice::create_Depth(): ERROR: Fail to open stream of Depth.");
00186 return FALSE;
00187 }
00188
00189
00190 NuiImageResolutionToSize(reso, (DWORD&)depth->m_xsize, (DWORD&)depth->m_ysize);
00191 depth->m_nfps = 30;
00192
00193 if (depth->m_data==NULL) depth->make_data();
00194
00195
00196 return TRUE;
00197 }
00198
00199
00200
00201 BOOL CKinectDevice::create_Skeleton(int profile)
00202 {
00203 if (context==NULL) {
00204 m_err_mesg = _T("CKinectDevice::create_Skeleton(): ERROR: context is NULL.");
00205 return FALSE;
00206 }
00207 if (depth==NULL) {
00208 m_err_mesg = _T("CKinectDevice::create_Skeleton(): ERROR: depth is NULL.");
00209 return FALSE;
00210 }
00211 if (skeleton==NULL) skeleton = new CKinectSkeleton();
00212
00213
00214 HANDLE hdl = skeleton->create(TRUE, FALSE, NULL);
00215 if (hdl==NULL) {
00216 delete_Skeleton();
00217 m_err_mesg = _T("CKinectDevice::create_Skeleton(): ERROR: Fail to create Skeleton.");
00218 return FALSE;
00219 }
00220
00221
00222 HRESULT hrt;
00223 DWORD ftracking = 0;
00224 DWORD streamode = 0;
00225 if (profile==KINECT_SKEL_PROFILE_UPPER) {
00226 ftracking = NUI_SKELETON_TRACKING_FLAG_ENABLE_SEATED_SUPPORT;
00227 ftracking |= NUI_SKELETON_TRACKING_FLAG_ENABLE_IN_NEAR_RANGE;
00228 streamode = NUI_IMAGE_STREAM_FLAG_ENABLE_NEAR_MODE;
00229 }
00230
00231
00232 hrt = context->NuiImageStreamSetImageFrameFlags(depth->m_stream, streamode);
00233 if (SUCCEEDED(hrt)) {
00234 if (profile==KINECT_SKEL_PROFILE_UPPER) depth->correct_map(-15, 8);
00235 }
00236
00237
00238 hrt = context->NuiSkeletonTrackingEnable(skeleton->m_handle, ftracking);
00239 if (FAILED(hrt)) {
00240 delete_Skeleton();
00241 m_err_mesg = _T("CKinectDevice::create_Skeleton(): ERROR: Fail to enable Skeleton Tracking.");
00242 return FALSE;
00243 }
00244
00245 return TRUE;
00246 }
00247
00248
00249
00250 BOOL CKinectDevice::create_Face(void)
00251 {
00252 if (context==NULL) {
00253 m_err_mesg = _T("CKinectDevice::create_Face(): ERROR: context is NULL.");
00254 return FALSE;
00255 }
00256 if (image==NULL) {
00257 m_err_mesg = _T("CKinectDevice::create_Face(): ERROR: image is NULL.");
00258 return FALSE;
00259 }
00260 if (depth==NULL) {
00261 m_err_mesg = _T("CKinectDevice::create_Face(): ERROR: depth is NULL.");
00262 return FALSE;
00263 }
00264
00265 if (face==NULL) face = new CKinectFaceTracker();
00266
00267 BOOL ret = face->create(image->m_xsize, image->m_ysize, image->m_data, depth->m_data);
00268 if (!ret) {
00269 delete_Face();
00270 m_err_mesg = _T("CKinectDevice::create_Face(): ERROR: Fail to create Face Tracker\nMaybe FaceTrackData.dll is not found.");
00271 }
00272
00273 return ret;
00274 }
00275
00276
00277
00278
00280
00281
00282 BOOL CKinectDevice::wait_Image(DWORD msec)
00283 {
00284 if (image==NULL) return FALSE;
00285 if (image->m_data==NULL) return FALSE;
00286
00287 BOOL ret = image->wait(msec);
00288 if (ret) {
00289 HRESULT hrt = context->NuiImageStreamGetNextFrame(image->m_stream, 0, &imageFrame);
00290 if (FAILED(hrt)) return FALSE;
00291
00292 NUI_LOCKED_RECT rect;
00293 imageFrame.pFrameTexture->LockRect(0, &rect, NULL, 0);
00294 long int len = rect.Pitch*image->m_ysize;
00295
00296 memcpy(image->m_data, (char*)rect.pBits, len);
00297 imageFrame.pFrameTexture->UnlockRect(0);
00298 context->NuiImageStreamReleaseFrame(image->m_stream, &imageFrame);
00299 }
00300
00301 return ret;
00302 }
00303
00304
00305
00306 BOOL CKinectDevice::wait_Depth(DWORD msec)
00307 {
00308 if (depth==NULL) return FALSE;
00309 if (depth->m_data==NULL) return FALSE;
00310
00311 BOOL ret = depth->wait(msec);
00312 if (ret) {
00313 HRESULT hrt = context->NuiImageStreamGetNextFrame(depth->m_stream, 0, &depthFrame);
00314 if (FAILED(hrt)) return FALSE;
00315
00316
00317 NUI_LOCKED_RECT rect;
00318 depthFrame.pFrameTexture->LockRect(0, &rect, NULL, 0);
00319 long int len = rect.Pitch*depth->m_ysize;
00320
00321 memcpy(depth->m_data, (char*)rect.pBits, len);
00322 depthFrame.pFrameTexture->UnlockRect(0);
00323 context->NuiImageStreamReleaseFrame(depth->m_stream, &depthFrame);
00324 }
00325
00326 return ret;
00327 }
00328
00329
00330
00331 int CKinectDevice::wait_Skeleton(int tuser, int duser, DWORD msec)
00332 {
00333 if (skeleton==NULL) return 0;
00334
00335 BOOL ret = skeleton->wait(msec);
00336 if (ret) {
00337 HRESULT hrt = context->NuiSkeletonGetNextFrame(0, &skltnFrame);
00338 if (smoothParam!=NULL && !FAILED(hrt)) {
00339 hrt = context->NuiTransformSmooth(&skltnFrame, smoothParam);
00340 }
00341 if (FAILED(hrt)) return FALSE;
00342
00343
00344 if (tuser>0) {
00345 skeleton->m_data = skltnFrame.SkeletonData[tuser-1];
00346 if (skeleton->m_data.eTrackingState!=NUI_SKELETON_TRACKED) {
00347 tuser = 0;
00348 }
00349 }
00350 if (tuser==0) {
00351 tuser = get_TrackingUser(duser);
00352 }
00353 if (tuser==0) return 0;
00354
00355
00356 for (int j=0; j<KINECT_JOINT_NUM; j++) {
00357 jointPosData[j] = skeleton->m_data.SkeletonPositions[j];
00358 }
00359 }
00360 else tuser = 0;
00361
00362 return tuser;
00363 }
00364
00365
00366
00367
00369
00370
00371 BOOL CKinectDevice::start_Detection(int profile)
00372 {
00373 BOOL ret = FALSE;
00374 if (m_state==NI_STATE_DETECT_EXEC) {
00375 m_err_mesg = _T("CKinectDevice::start_Detection(): WARNING: detection is already executed.");
00376 return ret;
00377 }
00378
00379 m_state = NI_STATE_DETECT_STARTING;
00380 clear_JointsData();
00381
00382 if (depth==NULL) create_Depth();
00383 depth->make_map();
00384
00385 ret = create_Skeleton(profile);
00386 if (ret) {
00387 m_state = NI_STATE_DETECT_EXEC;
00388 }
00389 else {
00390 m_state = NI_STATE_DETECT_STOPPING;
00391 delete_Skeleton();
00392 m_state = NI_STATE_DETECT_STOPPED;
00393 }
00394
00395
00396 if (ret) {
00397 BOOL infoff = context->NuiGetForceInfraredEmitterOff();
00398 if (infoff) ret = !context->NuiSetForceInfraredEmitterOff(FALSE);
00399 if (!ret) m_err_mesg = _T("CKinectDevice::start_Detection(): ERROR: Fail to Start Emitter.");
00400 }
00401
00402 return ret;
00403 }
00404
00405
00406
00407 BOOL CKinectDevice::stop_Detection(void)
00408 {
00409 if (m_state==NI_STATE_DETECT_STOPPED) {
00410 m_err_mesg = _T("CKinectDevice::stop_Detection(): WARNING: detection is already stopped.");
00411 return FALSE;
00412 }
00413
00414 m_state= NI_STATE_DETECT_STOPPING;
00415 context->NuiSetForceInfraredEmitterOff(TRUE);
00416
00417 ::Sleep(NI_STOP_WAIT_TIME);
00418 depth->delete_map();
00419 delete_Skeleton();
00420
00421 m_state = NI_STATE_DETECT_STOPPED;
00422
00423 return TRUE;
00424 }
00425
00426
00427
00428 int CKinectDevice::get_TrackingUser(int duser)
00429 {
00430 int ret = 0;
00431
00432 if (depth!=NULL && skeleton!=NULL) {
00433 depth->get_users();
00434 for (int i=0; i<KINECT_USERS_NUM; i++) {
00435 int idx = (duser + i) % KINECT_USERS_NUM;
00436 if (depth->userLabel[idx]>0) {
00437 skeleton->m_data = skltnFrame.SkeletonData[idx];
00438 if (skeleton->m_data.eTrackingState==NUI_SKELETON_TRACKED) {
00439 ret = idx + 1;
00440 break;
00441 }
00442 }
00443 }
00444 }
00445
00446 return ret;
00447 }
00448
00449
00450
00451
00453
00454
00455 void CKinectDevice::delete_Context(void)
00456 {
00457 if (context!=NULL) {
00458 context->Release();
00459 context->NuiShutdown();
00460 context = NULL;
00461 }
00462 return;
00463 }
00464
00465
00466
00467 void CKinectDevice::delete_Image(void)
00468 {
00469 if (image!=NULL) {
00470 delete(image);
00471 image = NULL;
00472 }
00473 return;
00474 }
00475
00476
00477
00478 void CKinectDevice::delete_Depth(void)
00479 {
00480 if (depth!=NULL) {
00481 delete(depth);
00482 depth = NULL;
00483 }
00484 return;
00485 }
00486
00487
00488
00489 void CKinectDevice::delete_Skeleton(void)
00490 {
00491 if (skeleton!=NULL) {
00492 if (context!=NULL) {
00493 context->NuiSkeletonTrackingDisable();
00494 }
00495 delete(skeleton);
00496 skeleton = NULL;
00497 }
00498 return;
00499 }
00500
00501
00502
00503 void CKinectDevice::delete_Face(void)
00504 {
00505 if (face!=NULL) {
00506 delete(face);
00507 face = NULL;
00508 }
00509 return;
00510 }
00511
00512
00513
00514
00516
00517
00518 CKinectImage::CKinectImage(void)
00519 {
00520 m_data = NULL;
00521 m_data_len = 0;
00522
00523 m_stream = NULL;
00524
00525 m_xsize = 0;
00526 m_ysize = 0;
00527 m_nfps = 0;
00528 }
00529
00530
00531
00532 void CKinectImage::free(void)
00533 {
00534 if (m_data!=NULL) {
00535 ::free(m_data);
00536 m_data = NULL;
00537 m_data_len = 0;
00538 }
00539 return;
00540 }
00541
00542
00543
00544 void CKinectImage::make_data(void)
00545 {
00546 if (m_xsize<=0 || m_ysize<=0) return;
00547
00548 m_data_len = m_xsize*m_ysize*4;
00549 m_data = (uByte*)malloc(m_data_len);
00550
00551 return;
00552 }
00553
00554
00555
00556
00558
00559
00560 CKinectDepth::CKinectDepth(void)
00561 {
00562 m_data = NULL;
00563 m_data_len = 0;
00564
00565 has_map = FALSE;
00566 m_xmap_i2d = NULL;
00567 m_ymap_i2d = NULL;
00568 m_xmap_d2i = NULL;
00569 m_ymap_d2i = NULL;
00570 m_map_len = 0;
00571
00572 m_stream = NULL;
00573
00574 m_xsize = 0;
00575 m_ysize = 0;
00576 m_nfps = 0;
00577 }
00578
00579
00580
00581 void CKinectDepth::free(void)
00582 {
00583 if (m_data!=NULL) {
00584 ::free(m_data);
00585 m_data = NULL;
00586 m_data_len = 0;
00587 }
00588
00589 delete_map();
00590
00591 return;
00592 }
00593
00594
00595
00596 void CKinectDepth::make_data(void)
00597 {
00598 if (m_xsize<=0 || m_ysize<=0) return;
00599
00600 m_data_len = m_xsize*m_ysize*2;
00601 m_data = (uByte*)malloc(m_data_len);
00602
00603 return;
00604 }
00605
00606
00607
00608 void CKinectDepth::make_map(void)
00609 {
00610 if (m_xsize<=0 || m_ysize<=0) return;
00611 if (has_map) delete_map();
00612
00613 int sz = m_xsize*m_ysize;
00614 int len = sizeof(int)*sz;
00615
00616 m_xmap_i2d = (int*)malloc(len);
00617 m_ymap_i2d = (int*)malloc(len);
00618 m_xmap_d2i = (int*)malloc(len);
00619 m_ymap_d2i = (int*)malloc(len);
00620
00621 if (m_xmap_i2d==NULL || m_ymap_i2d==NULL || m_xmap_d2i==NULL || m_ymap_d2i==NULL) {
00622 if (m_xmap_i2d!=NULL) { ::free(m_xmap_i2d); m_xmap_i2d = NULL;}
00623 if (m_ymap_i2d!=NULL) { ::free(m_ymap_i2d); m_ymap_i2d = NULL;}
00624 if (m_xmap_d2i!=NULL) { ::free(m_xmap_d2i); m_xmap_d2i = NULL;}
00625 if (m_ymap_d2i!=NULL) { ::free(m_ymap_d2i); m_ymap_d2i = NULL;}
00626 return;
00627 }
00628
00629 memset(m_xmap_i2d, 0, len);
00630 memset(m_ymap_i2d, 0, len);
00631 memset(m_xmap_d2i, 0, len);
00632 memset(m_ymap_d2i, 0, len);
00633
00634 long int ii, jj, kk;
00635 for (int j=0; j<m_ysize; j++) {
00636 for (int i=0; i<m_xsize; i++) {
00637
00638
00639
00640
00641
00642
00643 HRESULT hdr = NuiImageGetColorPixelCoordinatesFromDepthPixelAtResolution
00644 (NUI_IMAGE_RESOLUTION_640x480, NUI_IMAGE_RESOLUTION_640x480, NULL, (LONG)i, (LONG)j, 0, &ii, &jj);
00645
00646 if (ii>=0 && ii<m_xsize && jj>=0 && jj<m_ysize) {
00647 kk = jj*m_xsize + ii;
00648 m_xmap_i2d[kk] = (int)(i + 1);
00649 m_ymap_i2d[kk] = (int)(j + 1);
00650 }
00651 kk = j*m_xsize + i;
00652 m_xmap_d2i[kk] = ii;
00653 m_ymap_d2i[kk] = jj;
00654 }
00655 }
00656
00657
00658 for (int i=0; i<sz; i++) {
00659 m_xmap_i2d[i]--;
00660 m_ymap_i2d[i]--;
00661 if (m_xmap_i2d[i]<0 || m_ymap_i2d[i]<0) {
00662 m_xmap_i2d[i] = m_ymap_i2d[i] = -1;
00663 }
00664 }
00665
00666 m_map_len = sz;
00667 has_map = TRUE;
00668
00669 return;
00670 }
00671
00672
00673
00674 void CKinectDepth::delete_map(void)
00675 {
00676 if (m_xmap_i2d!=NULL) {
00677 ::free(m_xmap_i2d);
00678 m_xmap_i2d = NULL;
00679 }
00680 if (m_ymap_i2d!=NULL) {
00681 ::free(m_ymap_i2d);
00682 m_ymap_i2d = NULL;
00683 }
00684 if (m_xmap_d2i!=NULL) {
00685 ::free(m_xmap_d2i);
00686 m_xmap_d2i = NULL;
00687 }
00688 if (m_ymap_d2i!=NULL) {
00689 ::free(m_ymap_d2i);
00690 m_ymap_d2i = NULL;
00691 }
00692
00693 m_map_len = 0;
00694 has_map = FALSE;
00695
00696 return;
00697 }
00698
00699
00700
00701 void CKinectDepth::correct_map(int cx, int cy)
00702 {
00703 if (!has_map) make_map();
00704 if (!has_map) return;
00705
00706
00707 if (cx!=0 || cy!=0) {
00708 int sz = m_xsize*m_ysize;
00709 int i2d_x, i2d_y, d2i_x, d2i_y;
00710
00711 for (int i=0; i<sz; i++) {
00712 if (m_xmap_i2d[i]>=0) {
00713 i2d_x = m_xmap_i2d[i] + cx;
00714 i2d_y = m_ymap_i2d[i] + cy;
00715 if (i2d_x>=0 && i2d_x<m_xsize) m_xmap_i2d[i] = i2d_x;
00716 if (i2d_y>=0 && i2d_y<m_ysize) m_ymap_i2d[i] = i2d_y;
00717 }
00718
00719 d2i_x = m_xmap_d2i[i] - cx;
00720 d2i_y = m_ymap_d2i[i] - cy;
00721 if (d2i_x>=0 && d2i_x<m_xsize) m_xmap_d2i[i] = d2i_x;
00722 if (d2i_y>=0 && d2i_y<m_ysize) m_ymap_d2i[i] = d2i_y;
00723 }
00724 }
00725
00726 return;
00727 }
00728
00729
00730
00731 int CKinectDepth::get_user_index(int i, int j)
00732 {
00733 int val = 0;
00734 if (i<0 || j<0 || i>=m_xsize || j>=m_ysize) return val;
00735
00736 if (has_map) {
00737 int len = j*m_xsize + i;
00738 int ii = m_xmap_i2d[len];
00739 int jj = m_ymap_i2d[len];
00740 if (ii>=0 && jj>=0 && ii<m_xsize && jj<m_ysize) {
00741 val = m_data[(jj*m_xsize + ii)*2] & 0x07;
00742 }
00743 }
00744 else {
00745 val = m_data[(j*m_xsize + i)*2] & 0x07;
00746 }
00747
00748 if (val>KINECT_USERS_NUM) val = 0;
00749
00750 return val;
00751 }
00752
00753
00754
00755 uWord CKinectDepth::get_depth(int i, int j)
00756 {
00757 uWord val = 0;
00758 if (i<0 || j<0 || i>=m_xsize || j>=m_ysize) return val;
00759
00760 uWord* ptr = (uWord*)m_data;
00761 if (has_map) {
00762 int len = j*m_xsize + i;
00763 int ii = m_xmap_i2d[len];
00764 int jj = m_xmap_i2d[len];
00765 if (ii>=0 && jj>=0) {
00766 val = ::NuiDepthPixelToDepth(ptr[jj*m_xsize+ii]);
00767 }
00768 else {
00769 val = ::NuiDepthPixelToDepth(ptr[j*m_xsize+i]);
00770 }
00771 }
00772 else {
00773 val = ::NuiDepthPixelToDepth(ptr[j*m_xsize+i]);
00774 }
00775
00776 return val;
00777 }
00778
00779
00780
00781 void CKinectDepth::get_users(void)
00782 {
00783 memset(userLabel, 0, KINECT_USERS_NUM*sizeof(int));
00784
00785 for (int j=0; j<m_ysize; j++) {
00786 int lj = j*m_xsize;
00787 for (int i=0; i<m_xsize; i++) {
00788 int val = m_data[(lj + i)*2] & 0x07;
00789 if (val>0 && val<=KINECT_USERS_NUM) {
00790 userLabel[val-1]++;
00791 }
00792 }
00793 }
00794
00795 return;
00796 }
00797
00798
00799
00800 void CKinectDepth::get_image_coord(int* i, int* j)
00801 {
00802 if (i==NULL || j==NULL) return;
00803 if ((*i)<0 || (*j)<0 || (*i)>=m_xsize || (*j)>=m_ysize) {
00804 *i = *j = -1;
00805 return;
00806 }
00807
00808 if (has_map) {
00809 int len = (*j)*m_xsize + (*i);
00810 *i = m_xmap_d2i[len];
00811 *j = m_ymap_d2i[len];
00812 }
00813
00814 return;
00815 }
00816
00817
00818
00819
00821
00822
00823 CKinectSkeleton::CKinectSkeleton(void)
00824 {
00825 m_stream = NULL;
00826 }
00827
00828
00829
00830 void CKinectSkeleton::free(void)
00831 {
00832 return;
00833 }
00834
00835 #endif // ENABLE_KINECT_SDK
00836