Commit c13febc4 authored by Maria Dimashova's avatar Maria Dimashova

minor refactoring CvCapture_OpenNI::CvCapture_OpenNI

parent 36b2ff3c
...@@ -107,7 +107,7 @@ protected: ...@@ -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 ) ...@@ -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,26 +214,22 @@ CvCapture_OpenNI::CvCapture_OpenNI( int index ) ...@@ -215,26 +214,22 @@ CvCapture_OpenNI::CvCapture_OpenNI( int index )
outfile.close(); outfile.close();
status = context.RunXmlScriptFromFile( xmlFilename.c_str() ); status = context.RunXmlScriptFromFile( xmlFilename.c_str() );
if( status != XN_STATUS_OK )
{
std::cerr << "CvCapture_OpenNI::CvCapture_OpenNI : Failed to run xml script: "
<< std::string(xnGetStatusString(status)) << std::endl;
return;
}
// Remove temporary configuration file. // Remove temporary configuration file.
remove( xmlFilename.c_str() ); remove( xmlFilename.c_str() );
#else #else
status = context.RunXmlScript( XMLConfig.c_str() ); status = context.RunXmlScript( XMLConfig.c_str() );
#endif #endif
isContextInitialized = ( status == XN_STATUS_OK ); if( status != XN_STATUS_OK )
{
std::cerr << "CvCapture_OpenNI::CvCapture_OpenNI : Failed to run xml script: "
<< std::string(xnGetStatusString(status)) << std::endl;
return;
} }
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 ) ...@@ -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 ) ...@@ -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 ) ...@@ -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 ) ...@@ -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() ...@@ -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 )
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment