opencv_oni.patch

openni files reading - Mourad Boufarguine, 2011-05-17 02:05 pm

Download (3.5 kB)

 
modules/highgui/src/cap.cpp (working copy)
299 299
    if (! result)
300 300
        result = cvCreateFileCapture_QT (filename);
301 301
    #endif
302
    
302

  
303
	#ifdef HAVE_OPENNI
304
     if (! result)
305
        result = cvCreateFileCapture_OpenNI (filename);
306
    #endif
307

  
303 308
    if (! result)
304 309
        result = cvCreateFileCapture_Images (filename);
305 310

  
modules/highgui/src/cap_openni.cpp (working copy)
87 87
public:
88 88
    static const int INVALID_PIXEL_VAL = 0;
89 89

  
90
    CvCapture_OpenNI();
90
    CvCapture_OpenNI( const char* filename = 0 );
91 91
    virtual ~CvCapture_OpenNI();
92 92

  
93 93
    virtual double getProperty(int propIdx);
......
166 166
    return m_isOpened;
167 167
}
168 168

  
169
CvCapture_OpenNI::CvCapture_OpenNI()
169
CvCapture_OpenNI::CvCapture_OpenNI( const char* filename )
170 170
{
171 171
    XnStatus status = XN_STATUS_OK;
172 172

  
......
180 180
    // Initialize and configure the context.
181 181
    if( context.Init() == XN_STATUS_OK )
182 182
    {
183
		if(filename == 0)
184
		{
183 185
#ifdef HACK_WITH_XML
184
        // Write configuration to the temporary file.
185
        // This is a hack, because there is a bug in RunXmlScript().
186
        // TODO: remove hack when bug in RunXmlScript() will be fixed.
187
        std::string xmlFilename = cv::tempfile();
188
        std::ofstream outfile( xmlFilename.c_str() );
189
        outfile.write( XMLConfig.c_str(), XMLConfig.length() );
190
        outfile.close();
186
			// Write configuration to the temporary file.
187
			// This is a hack, because there is a bug in RunXmlScript().
188
			// TODO: remove hack when bug in RunXmlScript() will be fixed.
189
			std::string xmlFilename = cv::tempfile();
190
			std::ofstream outfile( xmlFilename.c_str() );
191
			outfile.write( XMLConfig.c_str(), XMLConfig.length() );
192
			outfile.close();
191 193

  
192
        status = context.RunXmlScriptFromFile( xmlFilename.c_str() );
194
			status = context.RunXmlScriptFromFile( xmlFilename.c_str() );
193 195

  
194
        // Remove temporary configuration file.
195
        remove( xmlFilename.c_str() );
196
			// Remove temporary configuration file.
197
			remove( xmlFilename.c_str() );
196 198
#else
197
        status = context.RunXmlScript( XMLConfig.c_str() );
199
	        status = context.RunXmlScript( XMLConfig.c_str() );
198 200
#endif
201
		}
202
		else
203
		{
204
			status = context.OpenFileRecording(filename);
205
		}
199 206
        m_isOpened = ( status == XN_STATUS_OK );
200 207
    }
201 208

  
......
637 644
    return 0;
638 645
}
639 646

  
647
CvCapture* cvCreateFileCapture_OpenNI( const char* filename )
648
{
649
    // TODO devices enumeration (if several Kinects)
650
    CvCapture_OpenNI* capture = new CvCapture_OpenNI(filename);
651

  
652
    if( capture->isOpened() )
653
        return capture;
654

  
655
    delete capture;
656
    return 0;
657
}
658

  
640 659
#endif
modules/highgui/src/precomp.hpp (working copy)
128 128
                                        double fps, CvSize frameSize, int is_color );
129 129
CvCapture* cvCreateCameraCapture_DShow( int index );
130 130
CvCapture* cvCreateCameraCapture_OpenNI( int index );
131
CvCapture* cvCreateFileCapture_OpenNI( const char* filename );
131 132
CvCapture* cvCreateCameraCapture_Android( int index );
132 133

  
133 134
CVAPI(int) cvHaveImageReader(const char* filename);