Index: modules/highgui/src/cap.cpp =================================================================== --- modules/highgui/src/cap.cpp (revision 5114) +++ modules/highgui/src/cap.cpp (working copy) @@ -299,7 +299,12 @@ if (! result) result = cvCreateFileCapture_QT (filename); #endif - + + #ifdef HAVE_OPENNI + if (! result) + result = cvCreateFileCapture_OpenNI (filename); + #endif + if (! result) result = cvCreateFileCapture_Images (filename); Index: modules/highgui/src/cap_openni.cpp =================================================================== --- modules/highgui/src/cap_openni.cpp (revision 5114) +++ modules/highgui/src/cap_openni.cpp (working copy) @@ -87,7 +87,7 @@ public: static const int INVALID_PIXEL_VAL = 0; - CvCapture_OpenNI(); + CvCapture_OpenNI( const char* filename = 0 ); virtual ~CvCapture_OpenNI(); virtual double getProperty(int propIdx); @@ -166,7 +166,7 @@ return m_isOpened; } -CvCapture_OpenNI::CvCapture_OpenNI() +CvCapture_OpenNI::CvCapture_OpenNI( const char* filename ) { XnStatus status = XN_STATUS_OK; @@ -180,22 +180,29 @@ // Initialize and configure the context. if( context.Init() == XN_STATUS_OK ) { + if(filename == 0) + { #ifdef HACK_WITH_XML - // Write configuration to the temporary file. - // This is a hack, because there is a bug in RunXmlScript(). - // TODO: remove hack when bug in RunXmlScript() will be fixed. - std::string xmlFilename = cv::tempfile(); - std::ofstream outfile( xmlFilename.c_str() ); - outfile.write( XMLConfig.c_str(), XMLConfig.length() ); - outfile.close(); + // Write configuration to the temporary file. + // This is a hack, because there is a bug in RunXmlScript(). + // TODO: remove hack when bug in RunXmlScript() will be fixed. + std::string xmlFilename = cv::tempfile(); + std::ofstream outfile( xmlFilename.c_str() ); + outfile.write( XMLConfig.c_str(), XMLConfig.length() ); + outfile.close(); - status = context.RunXmlScriptFromFile( xmlFilename.c_str() ); + status = context.RunXmlScriptFromFile( xmlFilename.c_str() ); - // Remove temporary configuration file. - remove( xmlFilename.c_str() ); + // Remove temporary configuration file. + remove( xmlFilename.c_str() ); #else - status = context.RunXmlScript( XMLConfig.c_str() ); + status = context.RunXmlScript( XMLConfig.c_str() ); #endif + } + else + { + status = context.OpenFileRecording(filename); + } m_isOpened = ( status == XN_STATUS_OK ); } @@ -637,4 +644,16 @@ return 0; } +CvCapture* cvCreateFileCapture_OpenNI( const char* filename ) +{ + // TODO devices enumeration (if several Kinects) + CvCapture_OpenNI* capture = new CvCapture_OpenNI(filename); + + if( capture->isOpened() ) + return capture; + + delete capture; + return 0; +} + #endif Index: modules/highgui/src/precomp.hpp =================================================================== --- modules/highgui/src/precomp.hpp (revision 5114) +++ modules/highgui/src/precomp.hpp (working copy) @@ -128,6 +128,7 @@ double fps, CvSize frameSize, int is_color ); CvCapture* cvCreateCameraCapture_DShow( int index ); CvCapture* cvCreateCameraCapture_OpenNI( int index ); +CvCapture* cvCreateFileCapture_OpenNI( const char* filename ); CvCapture* cvCreateCameraCapture_Android( int index ); CVAPI(int) cvHaveImageReader(const char* filename);