标签:style blog http ar color os 使用 sp for
通过Kinect SDK v2预览版,取得BodyIndex(人体区域)的方法和示例代码。
// Sensor IKinectSensor* pSensor; ……1 HRESULT hResult = S_OK; hResult = GetDefaultKinectSensor( &pSensor ); ……2 if( FAILED( hResult ) ){ std::cerr << "Error : GetDefaultKinectSensor" << std::endl; return -1; } hResult = pSensor->Open(); ……3 if( FAILED( hResult ) ){ std::cerr << "Error : IKinectSensor::Open()" << std::endl; return -1; }
// Source IBodyIndexFrameSource* pBodyIndexSource; ……1 hResult = pSensor->get_BodyIndexFrameSource( &pBodyIndexSource ); ……2 if( FAILED( hResult ) ){ std::cerr << "Error : IKinectSensor::get_BodyIndexFrameSource()" << std::endl; return -1; }
// Reader IBodyIndexFrameReader* pBodyIndexReader; ……1 hResult = pBodyIndexSource->OpenReader( &pBodyIndexReader ); ……2 if( FAILED( hResult ) ){ std::cerr << "Error : IBodyIndexFrameSource::OpenReader()" << std::endl; return -1; }
int width = 512; ……1 int height = 424; ……1 cv::Mat bodyIndexMat( height, width, CV_8UC3 ); ……2 cv::namedWindow( "BodyIndex" ); // Color Table cv::Vec3b color[6]; ……3 color[0] = cv::Vec3b( 255, 0, 0 ); color[1] = cv::Vec3b( 0, 255, 0 ); color[2] = cv::Vec3b( 0, 0, 255 ); color[3] = cv::Vec3b( 255, 255, 0 ); color[4] = cv::Vec3b( 255, 0, 255 ); color[5] = cv::Vec3b( 0, 255, 255 ); while( 1 ){ // Frame IBodyIndexFrame* pBodyIndexFrame = nullptr; ……4 hResult = pBodyIndexReader->AcquireLatestFrame( &pBodyIndexFrame ); ……5 if( SUCCEEDED( hResult ) ){ unsigned int bufferSize = 0; unsigned char* buffer = nullptr; hResult = pBodyIndexFrame->AccessUnderlyingBuffer( &bufferSize, &buffer ); ……6 if( SUCCEEDED( hResult ) ){ for( int y = 0; y < height; y++ ){ for( int x = 0; x < width; x++ ){ unsigned int index = y * width + x; if( buffer[index] != 0xff ){ bodyIndexMat.at<cv::Vec3b>( y, x ) = color[buffer[index]]; ……7 } else{ bodyIndexMat.at<cv::Vec3b>( y, x ) = cv::Vec3b( 0, 0, 0 ); ……7 } } } } } SafeRelease( pBodyIndexFrame ); // Show Window cv::imshow( "BodyIndex", bodyIndexMat ); if( cv::waitKey( 30 ) == VK_ESCAPE ){ break; } }
Kinect SDK v1 | Kinect SDK v2预览版 | |
---|---|---|
名称 | Player | BodyIndex |
检测支持人数 | 6人 | 6人 |
人体領域的値 | 1~6 | 0~5 |
非人体領域的値 | 0 | 255(0xff) |
【翻译】Kinect v2程序设计(C++) BodyIndex篇
标签:style blog http ar color os 使用 sp for
原文地址:http://www.cnblogs.com/TracePlus/p/4136368.html