Index: cap_openni.cpp =================================================================== --- cap_openni.cpp (revision 6514) +++ cap_openni.cpp (working copy) @@ -67,7 +67,7 @@ "" "" "" - "" + "" "" "" "" @@ -134,6 +134,7 @@ xn::DepthMetaData depthMetaData; XnMapOutputMode depthOutputMode; + bool m_isImageGeneratorPresent; xn::ImageGenerator imageGenerator; xn::ImageMetaData imageMetaData; XnMapOutputMode imageOutputMode; @@ -241,17 +242,34 @@ return; } - imageGenerator.Create( context ); + // enumerate the nodes to find if image generator is present + xn::NodeInfoList Imagelist; + status = context.EnumerateExistingNodes( Imagelist, XN_NODE_TYPE_IMAGE ); if( status != XN_STATUS_OK ) { - std::cerr << "CvCapture_OpenNI::CvCapture_OpenNI : Failed to create image generator: " - << std::string(xnGetStatusString(status)) << std::endl; + std::cerr << "CvCapture_OpenNI::CvCapture_OpenNI : Failed to enumerate Image Generators: " + << std::string(xnGetStatusString(status)) << std::endl; return; } + if(Imagelist.IsEmpty()) + { + m_isImageGeneratorPresent = FALSE; + } + else + { + m_isImageGeneratorPresent = TRUE; + imageGenerator.Create( context); + if( status != XN_STATUS_OK ) + { + std::cerr << "CvCapture_OpenNI::CvCapture_OpenNI : Failed to create image generator: " + << std::string(xnGetStatusString(status)) << std::endl; + return; + } + } // Set map output mode. CV_Assert( depthGenerator.SetMapOutputMode( depthOutputMode ) == XN_STATUS_OK ); // xn::DepthGenerator supports VGA only! (Jan 2011) - CV_Assert( imageGenerator.SetMapOutputMode( imageOutputMode ) == XN_STATUS_OK ); + CV_Assert( m_isImageGeneratorPresent ? ( imageGenerator.SetMapOutputMode( imageOutputMode ) == XN_STATUS_OK ) : TRUE); // Start generating data. status = context.StartGeneratingAll(); @@ -424,22 +442,28 @@ { if( propValue != 0.0 ) // "on" { - CV_Assert( imageGenerator.IsValid() ); - if( !depthGenerator.GetAlternativeViewPointCap().IsViewPointAs(imageGenerator) ) + // if no Image Generator is present i.e. ASUS XtionPro the imageGenerator cannot be used + if( m_isImageGeneratorPresent ) { - if( depthGenerator.GetAlternativeViewPointCap().IsViewPointSupported(imageGenerator) ) + CV_Assert( imageGenerator.IsValid() ); + if( !depthGenerator.GetAlternativeViewPointCap().IsViewPointAs(imageGenerator) ) { - XnStatus status = depthGenerator.GetAlternativeViewPointCap().SetViewPoint(imageGenerator); - if( status != XN_STATUS_OK ) - std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : " << xnGetStatusString(status) << std::endl; + if( depthGenerator.GetAlternativeViewPointCap().IsViewPointSupported(imageGenerator) ) + { + XnStatus status = depthGenerator.GetAlternativeViewPointCap().SetViewPoint(imageGenerator); + if( status != XN_STATUS_OK ) + std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : " << xnGetStatusString(status) << std::endl; + else + res = true; + } else - res = true; + std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : Unsupported viewpoint." << std::endl; } else - std::cerr << "CvCapture_OpenNI::setDepthGeneratorProperty : Unsupported viewpoint." << std::endl; + res = true; } else - res = true; + res = false; } else // "off" { @@ -484,6 +508,8 @@ bool CvCapture_OpenNI::setImageGeneratorProperty( int propIdx, double propValue ) { bool res = false; + if(!m_isImageGeneratorPresent) + return res; CV_Assert( imageGenerator.IsValid() ); @@ -536,7 +562,8 @@ return false; depthGenerator.GetMetaData( depthMetaData ); - imageGenerator.GetMetaData( imageMetaData ); + if(m_isImageGeneratorPresent) + imageGenerator.GetMetaData( imageMetaData ); return true; }