__declspec(dllexport) Status Recorder_create(Recorder*& rec, const char* fileName) { Recorder* vsl = new Recorder(); Status status = vsl->create(fileName); if (status == STATUS_OK) rec = vsl; else Recorder_destroy(vsl); return status; }
int main( int argc, char** argv ) { std::string sSource, sTarget; #pragma region check input parameters if( argc == 3 ) { sSource = argv[1]; sTarget = argv[2]; } else { cerr << "Usage: oniFixer source.oni target.oni\n" << endl; } #pragma endregion // Initial OpenNI if( OpenNI::initialize() != STATUS_OK ) { cerr << "OpenNI Initial Error: " << OpenNI::getExtendedError() << endl; return -1; } CNiTEProperty mNiTEProp; #pragma region Open and check source file CNIDevice mOniFile; if( !mOniFile.OpenDevice( sSource.c_str() ) ) { cerr << "Can't open ONI file" << endl; return -1; } // create Playback controller PlaybackControl* pPlay = mOniFile.mDeivce.getPlaybackControl(); int iDepthFrameNum, iColorFrameNum; if( pPlay != nullptr ) { pPlay->setRepeatEnabled( false ); pPlay->setSpeed( 0.0f ); iDepthFrameNum = pPlay->getNumberOfFrames( mOniFile.vsDepth ); iColorFrameNum = pPlay->getNumberOfFrames( mOniFile.vsColor ); cout << "This oni file have: " << iDepthFrameNum << " frames dpeth, " << iColorFrameNum << " frames color" << endl; } else { cerr << "Can't get playback controller, this may not a vaild oni file?" << endl; return -1; } // check NiTE required property if( mNiTEProp.LoadProperties( mOniFile.vsDepth ) ) { cout << "All required properties works, don't need to fix" << endl; return 0; } #pragma endregion #pragma region Create a physical device to read property cout << "\nOpen a physical device to read property" << endl; CNIDevice mPhysical; if( !mPhysical.OpenDevice( ANY_DEVICE, true ) ) { cerr << "Can't open physical device: " << OpenNI::getExtendedError() << endl; return -1; } // try to load property if( !mNiTEProp.LoadProperties( mPhysical.vsDepth ) ) { cout << "Can't prepare all required properties" << endl; return -1; } mPhysical.Close(); #pragma endregion #pragma region Create a virtual device to record // create recorder Recorder mRecorder; mRecorder.create( sTarget.c_str() ); // create virtual device cout << "\nCreate a virtual device to record" << endl; CNIDevice mVirtual; if( !mVirtual.OpenDevice( "\\OpenNI2\\VirtualDevice\\PS1080", !(mOniFile.vsColor.isValid()) ) ) { cerr << "Can't create virtual device" << endl; return -1; } // copy depth stream properties CopyGeneralProperties( mOniFile.vsDepth, mVirtual.vsDepth ); mNiTEProp.WriteProperties( mVirtual.vsDepth ); mOniFile.vsDepth.addNewFrameListener( new CFrameCopy( mVirtual.vsDepth ) ); mRecorder.attach( mVirtual.vsDepth ); // copy color stream properties if( mVirtual.vsColor.isValid() ) { CopyGeneralProperties( mOniFile.vsColor, mVirtual.vsColor ); mOniFile.vsColor.addNewFrameListener( new CFrameCopy( mVirtual.vsColor ) ); mRecorder.attach( mVirtual.vsColor ); } #pragma endregion // start cout << "Start to re-recorder\n"; mRecorder.start(); mVirtual.Start(); mOniFile.Start(); int iDepth = 0; while( true ) { // just seek by depth videostream pPlay->seek( mOniFile.vsDepth, ++iDepth ); cout << "." << flush; if( iDepth >= iDepthFrameNum ) break; } cout << "Done" << endl; // stop mRecorder.stop(); mOniFile.Stop(); mVirtual.Stop(); mOniFile.Close(); mVirtual.Close(); OpenNI::shutdown(); }