我不能讓周圍的SimpleOpenNI用於處理AO一個奇特的問題,我要求你的幫助。如何從depthMapRealWorld()方法高效地存儲過去的深度像素數據?
我想存儲像素深度數據的快照上離散的時間間隔(由.depthMapRealWorld()方法作爲PVector陣列返回),然後進一步處理它們進行演示。我嘗試將它們添加到ArrayList中,但似乎depthMapRealWorld()方法僅返回對當前深度數據的引用,而不是真正的數組。我嘗試了以下順序:
只是獲取數據並將其添加到arraylist中。在update()方法的每次調用中,整個數組列表都包含相同的PVector數組,即使零位置的數組添加了許多迭代!
然後,我提出的PVector陣列,其創建時間,一類的一部分沿。重寫了一下草圖,但沒有幫助。數組列表中的所有數組仍然相同。
最後,在類的構造函數,I「手動」複製XYZ座標從PVector陣列每向量的成int數組。這似乎解決了這個問題 - 陣列列表中的int數組現在彼此不同。但這個解決方案引入了嚴重的性能問
問題是:是否有更有效的方式來存儲這些PVector數組並保留它們的值?
代碼:
import processing.opengl.*;
import SimpleOpenNI.*;
SimpleOpenNI kinect;
float rotation = 0;
int time = 0;
ArrayList dissolver;
ArrayList<Integer> timer;
int pSize = 10;
Past past;
void setup() {
dissolver = new ArrayList();
timer = new ArrayList();
size(1024, 768, OPENGL);
kinect = new SimpleOpenNI(this);
kinect.enableDepth();
translate(width/2, height/2, -100);
rotateX(radians(180));
stroke(255);
}
void draw() {
background(0);
translate(width/2, height/2, 500);
rotateX(radians(180));
kinect.update();
stroke (255, 255, 255);
past = new Past (kinect.depthMapRealWorld(), time);
if (dissolver.size() == pSize) { //remove the oldest arraylist element if when list gets full
dissolver.remove(0); //
}
if (time % 20 == 0) {
dissolver.add (past);
Past p1 = (Past) dissolver.get (0);
float [][] o2 = p1.getVector();
println ("x coord of a random point at arraylist position 0: " + o2[50000][0]); //for testing
}
if (dissolver.size() == pSize-1) {
//dissolve();
}
time ++;
}
void dissolve() { //from the previous nonworking version; ignore
for (int offset = 0; offset < pSize-1; offset ++) {
PVector[] offPoints = (PVector[]) dissolver.get (offset);
int offTime = timer.get(offset);
for (int i = 0; i < offPoints.length; i+=10) {
int col = (time-offTime)*2; //why??
stroke (255, 0, col);
PVector currentPoint = offPoints[i];
if (currentPoint.z <1500) {
point(currentPoint.x, currentPoint.y, currentPoint.z); // - 2*(time-offTime) + random(0, 100)
}
}
}
}
class Past {
private PVector [] depth; //should contain this, not int
private float [][] depth1;
private int time;
Past (PVector [] now, int t) {
//should be like this: depth = now;
//clumsy and performancewise catastrophic solution below
depth1 = new float [now.length][3];
for (int i = 0; i< now.length; i+=10) {
PVector temp = now[i];
depth1 [i][0] = temp.x;
depth1 [i][1] = temp.y;
depth1 [i][2] = temp.z;
}
//arrayCopy(now, depth); this didn't work either
time = t;
}
float [][] getVector() {
return depth1;
}
int getTime() {
return time;
}
}
謝謝!我認爲這足以說:PVector [] frame = kinect.depthMapRealWorld(),然後將frame []添加到ArrayList。顯然不是這樣:) – Solipsy 2012-03-26 15:55:36