标签:style blog http io ar color os 使用 sp
Kinect SDK v2预览版的主要功能的使用介绍,基本上完成了。这次,是关于取得Body(人体姿势)方法的说明。
// SensorIKinectSensor* pSensor; ……1HRESULT hResult = S_OK;hResult = GetDefaultKinectSensor( &pSensor ); ……2if( FAILED( hResult ) ){std::cerr << "Error : GetDefaultKinectSensor" << std::endl;return -1;}hResult = pSensor->Open(); ……3if( FAILED( hResult ) ){std::cerr << "Error : IKinectSensor::Open()" << std::endl;return -1;}
// SourceIBodyFrameSource* pBodySource; ……1hResult = pSensor->get_BodyFrameSource( &pBodySource ); ……2if( FAILED( hResult ) ){std::cerr << "Error : IKinectSensor::get_BodyFrameSource()" << std::endl;return -1;}
// ReaderIBodyFrameReader* pBodyReader; ……1hResult = pBodySource->OpenReader( &pBodyReader ); ……2if( FAILED( hResult ) ){std::cerr << "Error : IBodyFrameSource::OpenReader()" << std::endl;return -1;}
// Coordinate MapperICoordinateMapper* pCoordinateMapper; ……1hResult = pSensor->get_CoordinateMapper( &pCoordinateMapper ); ……2if( FAILED( hResult ) ){std::cerr << "Error : IKinectSensor::get_CoordinateMapper()" << std::endl;return -1;}
int width = 1920;int height = 1080;unsigned int bufferSize = width * height * 4 * sizeof( unsigned char );cv::Mat bufferMat( height, width, CV_8UC4 );cv::Mat bodyMat( height / 2, width / 2, CV_8UC4 );cv::namedWindow( "Body" );// Color Tablecv::Vec3b color[6];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 ){// Color Frame ……1IColorFrame* pColorFrame = nullptr;hResult = pColorReader->AcquireLatestFrame( &pColorFrame );if( SUCCEEDED( hResult ) ){hResult = pColorFrame->CopyConvertedFrameDataToArray( bufferSize, reinterpret_cast<BYTE*>( bufferMat.data ), ColorImageFormat_Bgra );if( SUCCEEDED( hResult ) ){cv::resize( bufferMat, bodyMat, cv::Size(), 0.5, 0.5 );}}SafeRelease( pColorFrame );/* Body部分在列表1.6 */// Show Windowcv::imshow( "Body", bodyMat );if( cv::waitKey( 10 ) == VK_ESCAPE ){break;}}
// Body FrameIBodyFrame* pBodyFrame = nullptr; ……1hResult = pBodyReader->AcquireLatestFrame( &pBodyFrame ); ……2if( SUCCEEDED( hResult ) ){IBody* pBody[BODY_COUNT] = { 0 }; ……3hResult = pBodyFrame->GetAndRefreshBodyData( BODY_COUNT, pBody ); ……3if( SUCCEEDED( hResult ) ){for( int count = 0; count < BODY_COUNT; count++ ){BOOLEAN bTracked = false; ……4hResult = pBody[count]->get_IsTracked( &bTracked ); ……4if( SUCCEEDED( hResult ) && bTracked ){Joint joint[JointType::JointType_Count]; ……5hResult = pBody[count]->GetJoints( JointType::JointType_Count, joint ); ……5if( SUCCEEDED( hResult ) ){// Left Hand StateHandState leftHandState = HandState::HandState_Unknown; ……6hResult = pBody[count]->get_HandLeftState( &leftHandState ); ……6if( SUCCEEDED( hResult ) ){ColorSpacePoint colorSpacePoint = { 0 }; ……7hResult = pCoordinateMapper->MapCameraPointToColorSpace( joint[JointType::JointType_HandLeft].Position, &colorSpacePoint ); ……7if( SUCCEEDED( hResult ) ){int x = static_cast<int>( colorSpacePoint.X );int y = static_cast<int>( colorSpacePoint.Y );if( ( x >= 0 ) && ( x < width ) && ( y >= 0 ) && ( y < height ) ){if( leftHandState == HandState::HandState_Open ){ ……8cv::circle( bufferMat, cv::Point( x, y ), 75, cv::Scalar( 0, 128, 0 ), 5, CV_AA );}else if( leftHandState == HandState::HandState_Closed ){ ……8cv::circle( bufferMat, cv::Point( x, y ), 75, cv::Scalar( 0, 0, 128 ), 5, CV_AA );}else if( leftHandState == HandState::HandState_Lasso ){ ……8cv::circle( bufferMat, cv::Point( x, y ), 75, cv::Scalar( 128, 128, 0 ), 5, CV_AA );}}}}// Right Hand State/* 和左手一样,获取右手Hand State绘制状态。 */// Joint ……9for( int type = 0; type < JointType::JointType_Count; type++ ){ColorSpacePoint colorSpacePoint = { 0 };pCoordinateMapper->MapCameraPointToColorSpace( joint[type].Position, &colorSpacePoint );int x = static_cast< int >( colorSpacePoint.X );int y = static_cast< int >( colorSpacePoint.Y );if( ( x >= 0 ) && ( x < width ) && ( y >= 0 ) && ( y < height ) ){cv::circle( bufferMat, cv::Point( x, y ), 5, static_cast<cv::Scalar>( color[count] ), -1, CV_AA );}}}}}cv::resize( bufferMat, bodyMat, cv::Size(), 0.5, 0.5 );}}SafeRelease( pBodyFrame );
| Kinect SDK v1 | Kinect SDK v2预览版 | |
|---|---|---|
| 名称 | Skeleton | Body |
| 人体姿勢可以取得的人数 | 2人 | 6人 |
| Joint(关节) | 20处 | 25处 |
| Hand State(手的状態) | 2種類 | 3種類 |
| Hand State可以取得的人数 | 2人 | 2人 |



标签:style blog http io ar color os 使用 sp
原文地址:http://www.cnblogs.com/TracePlus/p/4138615.html