使用OpenNI录制和读取oni文件时出现问题



我试图将Kinect传感器的深度数据记录到文件中,然后使用openNi播放。我根据openNi的例子编写了一个简单的程序。我正在使用java包装器。

问题是,当我试图读取我正在录制的.oni文件时,我会收到以下错误:

org.OpenNI.StatusException: The file is corrupted!

这是我的录音代码:

Context context = new Context();
// add the NITE License 
License license = new License("PrimeSense", "0KOIk2JeIBYClPWVnMoRKn5cdY4=");   //     vendor, key
context.addLicense(license); 
DepthGenerator depth = DepthGenerator.create(context);
Recorder recorder = Recorder.create(context, "oni"); 
context.createProductionTree(recorder.getInfo());
recorder.setDestination(RecordMedium.FILE, "KinectLog.oni");
recorder.addNodeToRecording(depth);
context.startGeneratingAll();
int tmp = 0;
while(tmp < 100){
    tmp++;
    context.waitAnyUpdateAll();
    recorder.Record();
    System.out.println("recording");
}

也许我必须在录制后通过调用.release()方法来清理?记录器没有这样的方法。

这是我播放.oni文件的代码:

Context context = new Context();
// add the NITE License 
License license = new License("PrimeSense", "0KOIk2JeIBYClPWVnMoRKn5cdY4=");   // vendor, key
context.addLicense(license); 
context.openFileRecordingEx("KinectLog.oni");

是openFileRecordingEx强制转换StatusException。

有人知道我做错了什么吗?

我想明白了。我重写了一些代码,并在录制结束时添加了recorder.dispose()来释放记录器对象。

    public static void main(String[] args) {
    try {
        Context context = new Context();
        // add the NITE License 
        License license = new License("PrimeSense", "0KOIk2JeIBYClPWVnMoRKn5cdY4=");   // vendor, key
        context.addLicense(license); 
        DepthGenerator depth = DepthGenerator.create(context);

        Recorder recorder = Recorder.create(context, "oni"); 
        recorder.setDestination(RecordMedium.FILE, "KinectLog.oni");
        recorder.addNodeToRecording(depth);
        context.startGeneratingAll();
        int tmp = 0;
        while(tmp < 100){
            tmp++;
            context.waitAnyUpdateAll();
            recorder.Record();
            System.out.println("recording");
        }
        recorder.dispose();         
        }
        catch (GeneralException e) {
          System.out.println(e);
          System.exit(1);
        }
}

最新更新