xn::DepthGenerator::GetMetaData() resulting Segmentation fault (core dumped))
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?