0

我尝试用 Java 记录 oni 文件。当我录制一个文件时效果很好。但是当我想记录几个文件时,我遇到了问题。

这是一些测试代码:

package test;

import org.OpenNI.Context;
import org.OpenNI.DepthGenerator;
import org.OpenNI.GeneralException;
import org.OpenNI.ImageGenerator;
import org.OpenNI.OutArg;
import org.OpenNI.RecordMedium;
import org.OpenNI.Recorder;
import org.OpenNI.ScriptNode;

public class RecorderProblems {

    private static final String SAMPLE_XML_FILE = "KinectConfig.xml";
    private static final String TEST1_ONI_FILE = "Test1.oni";
    private static final String TEST2_ONI_FILE = "Test2.oni";

    public static void main(String[] args) {
        Context context = null;
        DepthGenerator depthGenerator = null;
        ImageGenerator imageGenerator = null;
        try {
            OutArg<ScriptNode> scriptNode = new OutArg<ScriptNode>();

            // Init Hardware
            System.out.println("Init Hardware");
            context = Context.createFromXmlFile(SAMPLE_XML_FILE, scriptNode);
            depthGenerator = DepthGenerator.create(context);
            imageGenerator = ImageGenerator.create(context);
            context.startGeneratingAll();

            // Record 1
            System.out.println("Start Record 1");
            Recorder recorder = Recorder.create(context, "oni");
            // Adding next line produces a corrupt file, but the program runs fine
//          context.createProductionTree(recorder.getInfo());
            recorder.setDestination(RecordMedium.FILE, TEST1_ONI_FILE);
            recorder.addNodeToRecording(depthGenerator);
            recorder.addNodeToRecording(imageGenerator);
            for (int i = 0; i < 100; i++) {
                context.waitOneUpdateAll(imageGenerator);
                recorder.Record();
            }
            recorder.removeNodeToRecording(depthGenerator);
            recorder.removeNodeToRecording(imageGenerator);
            recorder.dispose();

            // Record 2
            System.out.println("Start Record 2");
            recorder = Recorder.create(context, "oni");
            // Adding next line produces a corrupt file, but the program runs fine
//          context.createProductionTree(recorder.getInfo());
            recorder.setDestination(RecordMedium.FILE, TEST2_ONI_FILE);
            recorder.addNodeToRecording(depthGenerator);
            recorder.addNodeToRecording(imageGenerator);
            for (int i = 0; i < 100; i++) {
                context.waitOneUpdateAll(imageGenerator);
                recorder.Record();
            }
            recorder.removeNodeToRecording(depthGenerator);
            recorder.removeNodeToRecording(imageGenerator);
            recorder.dispose();
        } catch (GeneralException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            // End Hardware
            System.out.println("End Hardware");
            depthGenerator.dispose();
            depthGenerator = null;
            imageGenerator.dispose();
            imageGenerator = null;
            context.release();
            context.dispose();
        }
    }
}

当我尝试为第二条记录设置目标时,我得到一个 StatusException“输入指针为空”。

如果我添加未注释的行,程序运行良好,但创建的 oni 文件不可读。(我不知道这条线到底是做什么的。)

我还尝试重新初始化上下文。起初这工作得很好,但是当我尝试记录几个文件时,我在重新初始化时也遇到了问题。这是一些示例代码:

package test;

import org.OpenNI.Context;
import org.OpenNI.DepthGenerator;
import org.OpenNI.GeneralException;
import org.OpenNI.ImageGenerator;
import org.OpenNI.OutArg;
import org.OpenNI.RecordMedium;
import org.OpenNI.Recorder;
import org.OpenNI.ScriptNode;

public class RecorderProblems {

    private static final String SAMPLE_XML_FILE = "KinectConfig.xml";

    public static void main(String[] args) {
        Context context = null;
        DepthGenerator depthGenerator = null;
        ImageGenerator imageGenerator = null;
        try {
            OutArg<ScriptNode> scriptNode = new OutArg<ScriptNode>();

            // Record 1
            for (int i = 0; i < 25; i++) {
                System.out.println("Run " + i);
                // Init Hardware
                System.out.println("Init Hardware " + i);
                context = Context
                        .createFromXmlFile(SAMPLE_XML_FILE, scriptNode);
                depthGenerator = DepthGenerator.create(context);
                imageGenerator = ImageGenerator.create(context);
                context.startGeneratingAll();

                System.out.println("Start Record " + i);
                Recorder recorder = Recorder.create(context, "oni");
                recorder.setDestination(RecordMedium.FILE, "test_" + i + ".oni");
                recorder.addNodeToRecording(depthGenerator);
                recorder.addNodeToRecording(imageGenerator);
                for (int j = 0; j < 100; j++) {
                    context.waitOneUpdateAll(imageGenerator);
                    recorder.Record();
                }
                recorder.removeNodeToRecording(depthGenerator);
                recorder.removeNodeToRecording(imageGenerator);
                recorder.dispose();

                System.out.println("End Hardware " + i);
                depthGenerator.dispose();
                depthGenerator = null;
                imageGenerator.dispose();
                imageGenerator = null;
                context.release();
                context.dispose();
            }

        } catch (GeneralException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

在第三次运行时,我得到了一个 StatusExcption “等待新数据时发生超时!”。

有没有人记录文件的经验?不知道是不是我用的库不对,还是OpenNI(用Java)的问题?

顺便说一句,我使用 OpenNI 1.5.2.23 和 Kinect 相机。XML 配置文件“KinectConfig.xml”是 OpenNI 示例附带的默认 XML 文件。我只是重命名了它。

谢谢你的帮助

4

2 回答 2

0

你为什么把事情搞得这么复杂?您可以为此使用Android 库

于 2013-03-06T13:27:29.913 回答
0

我有读取 VGA 分辨率深度和 rgb 投注相同超时错误的问题。如果我将深度或 rgb 的分辨率降低到四分之一 vga,一切正常。

于 2014-01-23T17:07:11.940 回答