@ -127,6 +127,7 @@ protected:
// OpenNI context
xn : : Context context ;
bool m_isOpened ;
bool m_isDepthGeneratorPresent ;
bool m_isImageGeneratorPresent ;
// Data generators with its metadata
@ -229,6 +230,21 @@ CvCapture_OpenNI::CvCapture_OpenNI( int index )
}
// Associate generators with context.
// enumerate the nodes to find if depth generator is present
xn : : NodeInfoList depthList ;
status = context . EnumerateExistingNodes ( depthList , XN_NODE_TYPE_DEPTH ) ;
if ( status ! = XN_STATUS_OK )
{
std : : cerr < < " CvCapture_OpenNI::CvCapture_OpenNI : Failed to enumerate depth generators: "
< < std : : string ( xnGetStatusString ( status ) ) < < std : : endl ;
return ;
}
if ( depthList . IsEmpty ( ) )
{
std : : cerr < < " CvCapture_OpenNI::CvCapture_OpenNI : The device doesn't have depth generator. Such devices aren't supported now. " < < std : : endl ;
return ;
}
m_isDepthGeneratorPresent = true ;
status = depthGenerator . Create ( context ) ;
if ( status ! = XN_STATUS_OK )
{
@ -238,8 +254,8 @@ CvCapture_OpenNI::CvCapture_OpenNI( int index )
}
// enumerate the nodes to find if image generator is present
xn : : NodeInfoList Imagel ist;
status = context . EnumerateExistingNodes ( Imagel ist, XN_NODE_TYPE_IMAGE ) ;
xn : : NodeInfoList imageL ist;
status = context . EnumerateExistingNodes ( imageL ist, XN_NODE_TYPE_IMAGE ) ;
if ( status ! = XN_STATUS_OK )
{
std : : cerr < < " CvCapture_OpenNI::CvCapture_OpenNI : Failed to enumerate image generators: "
@ -247,10 +263,10 @@ CvCapture_OpenNI::CvCapture_OpenNI( int index )
return ;
}
if ( ! Imagel ist. IsEmpty ( ) )
if ( ! imageL ist. IsEmpty ( ) )
{
m_isImageGeneratorPresent = true ;
imageGenerator . Create ( context ) ;
status = imageGenerator . Create ( context ) ;
if ( status ! = XN_STATUS_OK )
{
std : : cerr < < " CvCapture_OpenNI::CvCapture_OpenNI : Failed to create image generator: "
@ -390,12 +406,18 @@ bool CvCapture_OpenNI::setProperty( int propIdx, double propValue )
double CvCapture_OpenNI : : getDepthGeneratorProperty ( int propIdx )
{
CV_Assert ( depthGenerator . IsValid ( ) ) ;
double propValue = 0 ;
if ( ! m_isDepthGeneratorPresent )
return propValue ;
CV_Assert ( depthGenerator . IsValid ( ) ) ;
switch ( propIdx )
{
case CV_CAP_PROP_OPENNI_GENERATOR_PRESENT :
CV_Assert ( m_isDepthGeneratorPresent ) ;
propValue = 1. ;
break ;
case CV_CAP_PROP_FRAME_WIDTH :
propValue = depthOutputMode . nXRes ;
break ;
@ -417,7 +439,11 @@ double CvCapture_OpenNI::getDepthGeneratorProperty( int propIdx )
case CV_CAP_PROP_OPENNI_REGISTRATION :
propValue = depthGenerator . GetAlternativeViewPointCap ( ) . IsViewPointAs ( imageGenerator ) ? 1.0 : 0.0 ;
default :
CV_Error ( CV_StsBadArg , " Depth generator does not support such parameter for getting. \n " ) ;
{
std : : stringstream ss ;
ss < < " Depth generator does not support such parameter (propIdx= " < < propIdx < < " ) for getting. \n " ;
CV_Error ( CV_StsBadArg , ss . str ( ) . c_str ( ) ) ;
}
}
return propValue ;
@ -468,7 +494,11 @@ bool CvCapture_OpenNI::setDepthGeneratorProperty( int propIdx, double propValue
}
break ;
default :
CV_Error ( CV_StsBadArg , " Unsupported depth generator property. \n " ) ;
{
std : : stringstream ss ;
ss < < " Depth generator does not support such parameter (propIdx= " < < propIdx < < " ) for setting. \n " ;
CV_Error ( CV_StsBadArg , ss . str ( ) . c_str ( ) ) ;
}
}
return isSet ;
@ -476,18 +506,18 @@ bool CvCapture_OpenNI::setDepthGeneratorProperty( int propIdx, double propValue
double CvCapture_OpenNI : : getImageGeneratorProperty ( int propIdx )
{
double propValue = 0 ;
double propValue = 0. ;
if ( ! m_isImageGeneratorPresent )
return propValue ;
if ( propIdx = = CV_CAP_PROP_OPENNI_IMAGE_GENERATOR_PRESENT )
propValue = m_isImageGeneratorPresent ? 1. : 0. ;
else
{
CV_Assert ( imageGenerator . IsValid ( ) ) ;
switch ( propIdx )
{
case CV_CAP_PROP_OPENNI_GENERATOR_PRESENT :
CV_Assert ( m_isImageGeneratorPresent ) ;
propValue = 1. ;
break ;
case CV_CAP_PROP_FRAME_WIDTH :
propValue = imageOutputMode . nXRes ;
break ;
@ -498,9 +528,13 @@ double CvCapture_OpenNI::getImageGeneratorProperty( int propIdx )
propValue = imageOutputMode . nFPS ;
break ;
default :
CV_Error ( CV_StsBadArg , " Image generator does not support such parameter for getting. \n " ) ;
{
std : : stringstream ss ;
ss < < " Image generator does not support such parameter (propIdx= " < < propIdx < < " ) for getting. \n " ;
CV_Error ( CV_StsBadArg , ss . str ( ) . c_str ( ) ) ;
}
}
return propValue ;
}
@ -550,7 +584,11 @@ bool CvCapture_OpenNI::setImageGeneratorProperty( int propIdx, double propValue
break ;
}
default :
CV_Error ( CV_StsBadArg , " Unsupported image generator property. \n " ) ;
{
std : : stringstream ss ;
ss < < " Image generator does not support such parameter (propIdx= " < < propIdx < < " ) for setting. \n " ;
CV_Error ( CV_StsBadArg , ss . str ( ) . c_str ( ) ) ;
}
}
return isSet ;