minor refactoring CvCapture_OpenNI::CvCapture_OpenNI

This commit is contained in:
Maria Dimashova 2012-03-15 09:59:23 +00:00
parent 36b2ff3cf3
commit c13febc4d4

View File

@ -107,7 +107,7 @@ protected:
IplImage iplHeader; IplImage iplHeader;
}; };
static const int outputTypesCount = 7; static const int outputMapsTypesCount = 7;
IplImage* retrieveDepthMap(); IplImage* retrieveDepthMap();
IplImage* retrievePointCloudMap(); IplImage* retrievePointCloudMap();
@ -177,7 +177,6 @@ CvCapture_OpenNI::CvCapture_OpenNI( int index )
depthOutputMode.nFPS = imageOutputMode.nFPS = 30; depthOutputMode.nFPS = imageOutputMode.nFPS = 30;
m_isOpened = false; m_isOpened = false;
bool isContextInitialized = false;
// Initialize and configure the context. // Initialize and configure the context.
if( context.Init() == XN_STATUS_OK ) if( context.Init() == XN_STATUS_OK )
@ -215,6 +214,12 @@ CvCapture_OpenNI::CvCapture_OpenNI( int index )
outfile.close(); outfile.close();
status = context.RunXmlScriptFromFile( xmlFilename.c_str() ); status = context.RunXmlScriptFromFile( xmlFilename.c_str() );
// Remove temporary configuration file.
remove( xmlFilename.c_str() );
#else
status = context.RunXmlScript( XMLConfig.c_str() );
#endif
if( status != XN_STATUS_OK ) if( status != XN_STATUS_OK )
{ {
std::cerr << "CvCapture_OpenNI::CvCapture_OpenNI : Failed to run xml script: " std::cerr << "CvCapture_OpenNI::CvCapture_OpenNI : Failed to run xml script: "
@ -222,19 +227,9 @@ CvCapture_OpenNI::CvCapture_OpenNI( int index )
return; return;
} }
// Remove temporary configuration file.
remove( xmlFilename.c_str() );
#else
status = context.RunXmlScript( XMLConfig.c_str() );
#endif
isContextInitialized = ( status == XN_STATUS_OK );
}
if( isContextInitialized )
{
// Associate generators with context. // Associate generators with context.
status = depthGenerator.Create( context ); status = depthGenerator.Create( context );
if( status != XN_STATUS_OK )\ if( status != XN_STATUS_OK )
{ {
std::cerr << "CvCapture_OpenNI::CvCapture_OpenNI : Failed to create depth generator: " std::cerr << "CvCapture_OpenNI::CvCapture_OpenNI : Failed to create depth generator: "
<< std::string(xnGetStatusString(status)) << std::endl; << std::string(xnGetStatusString(status)) << std::endl;
@ -246,10 +241,11 @@ CvCapture_OpenNI::CvCapture_OpenNI( int index )
status = context.EnumerateExistingNodes( Imagelist, XN_NODE_TYPE_IMAGE ); status = context.EnumerateExistingNodes( Imagelist, XN_NODE_TYPE_IMAGE );
if( status != XN_STATUS_OK ) if( status != XN_STATUS_OK )
{ {
std::cerr << "CvCapture_OpenNI::CvCapture_OpenNI : Failed to enumerate Image Generators: " std::cerr << "CvCapture_OpenNI::CvCapture_OpenNI : Failed to enumerate image generators: "
<< std::string(xnGetStatusString(status)) << std::endl; << std::string(xnGetStatusString(status)) << std::endl;
return; return;
} }
if(Imagelist.IsEmpty()) if(Imagelist.IsEmpty())
{ {
m_isImageGeneratorPresent = FALSE; m_isImageGeneratorPresent = FALSE;
@ -257,7 +253,7 @@ CvCapture_OpenNI::CvCapture_OpenNI( int index )
else else
{ {
m_isImageGeneratorPresent = TRUE; m_isImageGeneratorPresent = TRUE;
imageGenerator.Create( context); imageGenerator.Create( context );
if( status != XN_STATUS_OK ) if( status != XN_STATUS_OK )
{ {
std::cerr << "CvCapture_OpenNI::CvCapture_OpenNI : Failed to create image generator: " std::cerr << "CvCapture_OpenNI::CvCapture_OpenNI : Failed to create image generator: "
@ -268,7 +264,7 @@ CvCapture_OpenNI::CvCapture_OpenNI( int index )
// Set map output mode. // Set map output mode.
CV_Assert( depthGenerator.SetMapOutputMode( depthOutputMode ) == XN_STATUS_OK ); // xn::DepthGenerator supports VGA only! (Jan 2011) CV_Assert( depthGenerator.SetMapOutputMode( depthOutputMode ) == XN_STATUS_OK ); // xn::DepthGenerator supports VGA only! (Jan 2011)
CV_Assert( m_isImageGeneratorPresent ? ( imageGenerator.SetMapOutputMode( imageOutputMode ) == XN_STATUS_OK ) : TRUE); CV_Assert( m_isImageGeneratorPresent ? ( imageGenerator.SetMapOutputMode( imageOutputMode ) == XN_STATUS_OK ) : TRUE );
// Start generating data. // Start generating data.
status = context.StartGeneratingAll(); status = context.StartGeneratingAll();
@ -285,7 +281,7 @@ CvCapture_OpenNI::CvCapture_OpenNI( int index )
return; return;
} }
outputMaps.resize( outputTypesCount ); outputMaps.resize( outputMapsTypesCount );
m_isOpened = true; m_isOpened = true;
} }
@ -756,7 +752,7 @@ IplImage* CvCapture_OpenNI::retrieveGrayImage()
IplImage* CvCapture_OpenNI::retrieveFrame( int outputType ) IplImage* CvCapture_OpenNI::retrieveFrame( int outputType )
{ {
IplImage* image = 0; IplImage* image = 0;
CV_Assert( outputType < outputTypesCount && outputType >= 0); CV_Assert( outputType < outputMapsTypesCount && outputType >= 0);
if( outputType == CV_CAP_OPENNI_DEPTH_MAP ) if( outputType == CV_CAP_OPENNI_DEPTH_MAP )
{ {