void initialize() { // Sensorを取得 ERROR_CHECK( GetDefaultKinectSensor( &kinect ) ); ERROR_CHECK( kinect->Open() ); BOOLEAN isOpen; ERROR_CHECK( kinect->get_IsOpen( &isOpen ) ); if( !isOpen ){ throw std::runtime_error( "failed IKinectSensor::get_IsOpen( &isOpen )" ); } ERROR_CHECK( kinect->get_CoordinateMapper( &coordinateMapper ) ); // Color Frame Sourceを取得、Color Frame Readerを開く CComPtr<IColorFrameSource> colorFrameSource; ERROR_CHECK( kinect->get_ColorFrameSource( &colorFrameSource ) ); ERROR_CHECK( colorFrameSource->OpenReader( &colorFrameReader ) ); CComPtr<IFrameDescription> colorFrameDescription; ERROR_CHECK( colorFrameSource->CreateFrameDescription( colorFormat, &colorFrameDescription ) ); ERROR_CHECK( colorFrameDescription->get_Width( &colorWidth ) ); ERROR_CHECK( colorFrameDescription->get_Height( &colorHeight ) ); ERROR_CHECK( colorFrameDescription->get_BytesPerPixel( &colorBytesPerPixel ) ); colorBuffer.resize( colorWidth * colorHeight * colorBytesPerPixel ); // Depth Frame Sourceを取得、Depth Frame Readerを開く CComPtr<IDepthFrameSource> depthFrameSource; ERROR_CHECK( kinect->get_DepthFrameSource( &depthFrameSource ) ); ERROR_CHECK( depthFrameSource->OpenReader( &depthFrameReader ) ); CComPtr<IFrameDescription> depthFrameDescription; ERROR_CHECK( depthFrameSource->get_FrameDescription( &depthFrameDescription ) ); ERROR_CHECK( depthFrameDescription->get_Width( &depthWidth ) ); ERROR_CHECK( depthFrameDescription->get_Height( &depthHeight ) ); ERROR_CHECK( depthFrameDescription->get_BytesPerPixel( &depthBytesPerPixel ) ); depthBuffer.resize( depthWidth * depthHeight ); // Fusionの初期化 initializeFusion(); }
// Initialize void Kinect::initialize() { cv::setUseOptimized( true ); // Initialize Sensor initializeSensor(); // Initialize Color initializeColor(); // Initialize Depth initializeDepth(); // Initialize Fusion initializeFusion(); // Wait a Few Seconds until begins to Retrieve Data from Sensor ( about 2000-[ms] ) std::this_thread::sleep_for( std::chrono::seconds( 2 ) ); }