我尝试使用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文件。我刚刚重命名了。
感谢您的帮助
答案 0 :(得分:0)
你为什么这么复杂? 您可以使用Android libraries 。
答案 1 :(得分:0)
我有读取VGA分辨率深度和rgb投注相同超时错误的问题。如果我将任一深度或rgb的分辨率降低到四分之一vga一切正常。