首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >simple-openni / processing -仅在特定z深度记录

simple-openni / processing -仅在特定z深度记录
EN

Stack Overflow用户
提问于 2012-07-24 04:40:32
回答 1查看 1.6K关注 0票数 0

我按照simple-openni库中的RecorderPlay示例进行处理:

http://code.google.com/p/simple-openni/

它记录到ONI文件,这是一种保留深度和rgb信息的视频格式。不过目前,它捕获了整个图像,我希望能够捕获特定的z深度范围。有没有人知道这是否可能?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-24 07:27:44

我不认为您可以配置要记录的深度范围,但您可以做的是处理从.oni记录中读取的信息:

代码语言:javascript
复制
import SimpleOpenNI.*;

SimpleOpenNI  context;
boolean       recordFlag = true;
boolean       saving = false;
int frames = 0;
int savedFrames = 0;
//change these two values as you wish:
float minZ = 100;
float maxZ = 500;

void setup(){
  context = new SimpleOpenNI(this);

  if(! recordFlag){
    if(! context.openFileRecording("test.oni") ){
      println("can't find recording !!!!");
      exit();
    }
    context.enableDepth();
  }else{  
    // recording
    context.enableDepth();
    // setup the recording 
    context.enableRecorder(SimpleOpenNI.RECORD_MEDIUM_FILE,"test.oni");
    // select the recording channels
    context.addNodeToRecording(SimpleOpenNI.NODE_DEPTH,SimpleOpenNI.CODEC_16Z_EMB_TABLES);
  }
  // set window size 
  if((context.nodes() & SimpleOpenNI.NODE_DEPTH) != 0)
    size(context.depthWidth() , context.depthHeight());
  else 
    exit();
}
void draw()
{
  background(0);
  context.update();
  if((context.nodes() & SimpleOpenNI.NODE_DEPTH) != 0) image(context.depthImage(),0,0);
  if(recordFlag) frames++;
  if(saving && savedFrames < frames){
      delay(3000);//hack
      int i = savedFrames;
      int w = context.depthWidth();
      int h = context.depthHeight();
      PrintWriter output = createWriter(dataPath("frame_"+i+".ply"));
      output.println("ply");
      output.println("format ascii 1.0");
      output.println("element vertex " + (w*h));
      output.println("property float x");
      output.println("property float y");
      output.println("property float z");
      output.println("end_header\n");
      rect(random(width),random(height),100,100);
      int[]   depthMap = context.depthMap();
      int     index;
      PVector realWorldPoint;
      for(int y=0;y < h;y++){
        for(int x=0;x < w;x++){
          index = x + y * w;
          realWorldPoint = context.depthMapRealWorld()[index];
          if(realWorldPoint.z > minZ && realWorldPoint.z < maxZ)
            output.println(realWorldPoint.x + " " + realWorldPoint.y + " " + realWorldPoint.z);
        }
      }
      output.flush();
      output.close();
      println("saved " + (i+1) + " of " + frames);
      savedFrames++;
  }
}
void keyPressed(){
  if(key == ' '){
    if(recordFlag){
      saveStrings(dataPath("frames.txt"),split(frames+" ",' '));
      exit();
    }else saveONIToPLY();
  }
}
void saveONIToPLY(){
  frames = int(loadStrings(dataPath("frames.txt"))[0]);
  saving = true;
  println("recording " + frames + " frames");
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11620181

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档