SimpleOpenNI output issue. Only outputs last frame.
in
Contributed Library Questions
•
11 months ago
I have narrowed my problem down to the fact that it only outputs the very last frame. All the outputted files are exactly the same. I have spent days trying to find the problem, but I can't seem to fix it...
I'm on a tight deadline here and all help will be appreciated :)
The code looks like the following:
- /* --------------------------------------------------------------------------
- * SimpleOpenNI DepthMap3d Test
- * --------------------------------------------------------------------------
- * Processing Wrapper for the OpenNI/Kinect library
- * http://code.google.com/p/simple-openni
- * --------------------------------------------------------------------------
- * prog: Max Rheiner / Interaction Design / zhdk / http://iad.zhdk.ch/
- * date: 02/16/2011 (m/d/y)
- * ----------------------------------------------------------------------------
- */
- import SimpleOpenNI.*;
- import java.io.*;
- SimpleOpenNI context;
- float zoomF =0.3f;
- float rotX = radians(180); // by default rotate the hole scene 180deg around the x-axis,
- // the data from openni comes upside down
- float rotY = radians(0);
- // Size of kinect image
- int w = 640;
- int h = 480;
- float a = 0;
- // treshold filter initial value
- int fltValue = 950;
- // writing state indicator
- boolean write = false;
- // "recording" object. each vector element holds a coordinate map vector
- Vector <Object> recording = new Vector<Object>();
- int frameNum = 0;
- void setup()
- {
- frameRate(10);
- size(640,480,P3D); // strange, get drawing error in the cameraFrustum if i use P3D, in opengl there is no problem
- //context = new SimpleOpenNI(this,SimpleOpenNI.RUN_MODE_SINGLE_THREADED);
- context = new SimpleOpenNI(this);
- // disable mirror
- context.setMirror(false);
- context.enableDepth();
- // enable depthMap generation
- if(context.enableDepth() == false)
- {
- println("Can't open the depthMap, maybe the camera is not connected!");
- exit();
- return;
- }
- stroke(255,255,255);
- smooth();
- perspective(radians(45),
- float(width)/float(height),
- 10,150000);
- }
- void draw()
- {
- // update the cam
- context.update();
- background(0,0,0);
- // Get the raw depth as array of integers
- int[] depth = context.depthMap();
- // 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);
- rotateX(rotX);
- scale(zoomF);
- int index = 0;
- PVector[] frame = new PVector[19200];
- //translate(0,0,-1000); // set the rotation center of the scene 1000 infront of the camera
- stroke(255);
- PVector[] depthPoints = context.depthMapRealWorld();
- //print(depthPoints.length);
- for( int x = 0; x < w; x+=skip) {
- for( int y = 0; y < h; y+=skip) {
- int offset = x+y*w;
- //print(offset + " | ");
- // get the current point from the point array
- PVector currentPoint = depthPoints[ offset];
- // draw the current point
- point( currentPoint.x, currentPoint.y, currentPoint.z);
- //print(index + " | ");
- frame[index] = currentPoint;
- index++;
- }
- }
- //print(frame[1]);
- if (write == true) {
- print(frame[10000]);
- recording.add(frame);
- print("Added");
- }
- //print(recording.get(frameNum) + " | ");
- //frameNum++;
- }
- int currentFile = 0;
- void keyPressed() { // Press a key to save the data
- if (key == '1')
- {
- fltValue += 50;
- println("fltValue: " + fltValue);
- }
- else if (key == '2')
- {
- fltValue -= 50;
- println("fltValue: " + fltValue);
- }
- else if (key=='4'){
- if (write == true) {
- write = false;
- println( "recorded " + recording.size() + " frames.");
- // saveFile();
- // save
- Enumeration e = recording.elements();
- println("Stopped Recording " + currentFile);
- int i = 0;
- while (e.hasMoreElements()) {
- // Create one directory
- boolean success = (new File("out"+currentFile)).mkdir();
- PrintWriter output = createWriter("out"+currentFile+"/frame" + i++ +".txt");
- PVector [] frame = (PVector []) e.nextElement();
- //print(frame.length + " | ");
- for (int j = 0; j < frame.length; j++) {
- output.println(j + ", " + frame[j].x + ", " + frame[j].y + ", " + frame[j].z );
- }
- output.flush(); // Write the remaining data
- output.close();
- }
- currentFile++;
- }
- }
- else if (key == '3') {
- println("Started Recording "+currentFile);
- recording.clear();
- write = true;
- }
- }
1