Processing 将点云数据保存到文件中

Processing 将点云数据保存到文件中,processing,kinect,point-cloud-library,Processing,Kinect,Point Cloud Library,我有以下代码正在使用Kinect进行处理2: import org.openkinect.freenect.*; import org.openkinect.processing.*; // Kinect Library object Kinect kinect; // Angle for rotation float a = 0; // We'll use a lookup table so that we don't have to repeat the math over and o

我有以下代码正在使用Kinect进行
处理2

import org.openkinect.freenect.*;
import org.openkinect.processing.*;

// Kinect Library object
Kinect kinect;

// Angle for rotation
float a = 0;

// We'll use a lookup table so that we don't have to repeat the math over and over
float[] depthLookUp = new float[2048];

void setup() {
  // Rendering in P3D
  size(1200, 800, P3D);
  kinect = new Kinect(this);
  kinect.initDepth();

  // Lookup table for all possible depth values (0 - 2047)
  for (int i = 0; i < depthLookUp.length; i++) {
    depthLookUp[i] = rawDepthToMeters(i);
  }
}

void draw() {

  background(0);

  // Get the raw depth as array of integers
  int[] depth = kinect.getRawDepth();

  // We're just going to calculate and draw every 4th pixel (equivalent of 160x120)
  int skip = 4;

  // Translate and rotate
  translate(width/2, height/2, -50);
  rotateY(a);

  for (int x = 0; x < kinect.width; x += skip) {
    for (int y = 0; y < kinect.height; y += skip) {
      int offset = x + y*kinect.width;

      // Convert kinect data to world xyz coordinate
      int rawDepth = depth[offset];
      PVector v = depthToWorld(x, y, rawDepth);

      stroke(255);
      pushMatrix();
      // Scale up by 200
      float factor = 200;
      translate(v.x*factor, v.y*factor, factor-v.z*factor);
      // Draw a point
      point(0, 0);
      popMatrix();
    }
  }

  // Rotate
  a += 0.015f;
}

// These functions come from: http://graphics.stanford.edu/~mdfisher/Kinect.html
float rawDepthToMeters(int depthValue) {
  if (depthValue < 2047) {
    return (float)(1.0 / ((double)(depthValue) * -0.0030711016 + 3.3309495161));
  }
  return 0.0f;
}

PVector depthToWorld(int x, int y, int depthValue) {

  final double fx_d = 1.0 / 5.9421434211923247e+02;
  final double fy_d = 1.0 / 5.9104053696870778e+02;
  final double cx_d = 3.3930780975300314e+02;
  final double cy_d = 2.4273913761751615e+02;

  PVector result = new PVector();
  double depth =  depthLookUp[depthValue];//rawDepthToMeters(depthValue);
  result.x = (float)((x - cx_d) * depth * fx_d);
  result.y = (float)((y - cy_d) * depth * fy_d);
  result.z = (float)(depth);
  return result;
}
import org.openkinect.freenect.*;
导入org.openkinect.processing.*;
//Kinect库对象
Kinect-Kinect;
//旋转角度
浮点数a=0;
//我们将使用一个查找表,这样我们就不必一遍又一遍地重复计算
float[]depthLookUp=新的float[2048];
无效设置(){
//P3D渲染
尺寸(1200、800、P3D);
kinect=新的kinect(本);
kinect.initDepth();
//所有可能深度值的查找表(0-2047)
for(int i=0;i
我想将
pointcloud
数据保存在一个文件中,以便以后可以在另一个程序中导入它,例如
Cinema 4D


如何创建此文件?

处理有几个将数据保存到文件的功能,其中最简单的是

要使用
saveStrings()
函数,只需将想要保存的内容存储到
字符串数组中,然后将其与文件名一起传递到函数中即可

然后,您可以使用该函数将文件中的数据读回
字符串数组

如何将数据格式化为
字符串
完全取决于您。您可以将其存储为逗号分隔的值

更多信息可在中找到


如果要将数据存储到另一个程序可以读取的文件中,必须首先查找该文件所需的格式。首先,我将在基本文本编辑器中打开一些示例文件。

处理有几个将数据保存到文件的功能,其中最简单的是

要使用
saveStrings()
函数,只需将想要保存的内容存储到
字符串数组中,然后将其与文件名一起传递到函数中即可

然后,您可以使用该函数将文件中的数据读回
字符串数组

如何将数据格式化为
字符串
完全取决于您。您可以将其存储为逗号分隔的值

更多信息可在中找到

如果要将数据存储到另一个程序可以读取的文件中,必须首先查找该文件所需的格式。首先,我将在基本文本编辑器中打开一些示例文件