xn::DepthGenerator::GetMetaData() resulting Segmentation fault (core dumped))

asked 2014-03-09 23:05:09 -0600

Latif Anjum gravatar image

updated 2016-10-24 08:36:14 -0600

ngrennan gravatar image

Hi,

I have a .oni file and I want to process its data (convert it into and standard video for opencv plus depth a separate depth info file). However, the function xn::DepthGenerator::GetMetaData() is generating a run time error Segmentation fault (core dumped). Here is the code:

#include <iostream>
#include <fstream>
#include <sstream>
using namespace std;

// OpenNI Header
#include <XnCppWrapper.h>

int main( int argc, char** argv )
{
    if( argc == 1 )
    {
        cout << "Please give an ONI file to open" << endl;
    }

    // Initial OpenNI Context
    xn::Context xContext;
    xContext.Init();

    // open ONI file
    xn::Player xPlayer;
    xContext.OpenFileRecording( argv[1], xPlayer );
    xPlayer.SetRepeat( false );

    // Create depth generator
    xn::DepthGenerator xDepthGenerator;
    xDepthGenerator.Create( xContext );

    // get total frame number
    XnUInt32 uFrames;
    xPlayer.GetNumFrames( xDepthGenerator.GetName(), uFrames );
    cout << "Total " << uFrames << " frames" << endl;

    // Start
    xContext.StartGeneratingAll();

    // main loop
    for( unsigned int i = 0; i < uFrames; ++ i )
    {
        xDepthGenerator.WaitAndUpdateData();
        cout << i << "/" << uFrames << endl;

        // get value
        xn::DepthMetaData xDepthMap;
        xDepthGenerator.GetMetaData( xDepthMap ); //generating Core Dumped error
        cout <<"Metadata working" <<endl; 
 /*     
other code
*/
    }

    // stop
    xContext.StopGeneratingAll();

    // release resource
    xContext.Shutdown();

    return 0;
}

I have tested the code line by line and the error comes when GetMetaData() function is executed. Any clues?

edit retag flag offensive close merge delete