/* -------------------------------------------------------------------------- * SimpleOpenNI Record/Play 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: 03/16/2011 (m/d/y) * ---------------------------------------------------------------------------- * For playing the recorded file, just set recordFlag to false * All files should be in the data subfolder of the current project, abs. * path work as well * ---------------------------------------------------------------------------- */ import SimpleOpenNI.*; SimpleOpenNI context, context2; boolean recordFlag = false; void setup() { context = new SimpleOpenNI(this); context2 = new SimpleOpenNI(this); // playing, this works without the camera if ( context.openFileRecording("/Users/rtwomey/Movies/puppet/kinect_recordings/20120719_184947.oni") == false) { println("can't open recording !!!!"); exit(); } // it's possible to run the sceneAnalyzer over the recorded data strea if ( context.enableScene() == false) { println("can't setup scene!!!!"); exit(); return; } println("File 1 has " + context.framesPlayer() + " frames."); // RECORDING 2 // playing, this works without the camera if ( context2.openFileRecording("/Users/rtwomey/Movies/puppet/kinect_recordings/20120812_125613.oni") == false) { println("can't open recording file 2!!!!"); exit(); } // it's possible to run the sceneAnalyzer over the recorded data strea if ( context2.enableScene() == false) { println("can't setup scene!!!!"); exit(); return; } println("File 2 has " + context2.framesPlayer() + " frames."); // WINDOW SETUP if ((context.nodes() & SimpleOpenNI.NODE_DEPTH) != 0) { if ((context.nodes() & SimpleOpenNI.NODE_IMAGE) != 0) // depth + rgb size(context.depthWidth() + 10 + context.rgbWidth(), context.depthHeight() > context.rgbHeight()? context.depthHeight()*2:context.rgbHeight()*2); else // only depth size(context.depthWidth(), context.depthHeight()*2); } else exit(); } void draw() { // update context.update(); context2.update(); background(200, 0, 0); // draw the context1 data if ((context.nodes() & SimpleOpenNI.NODE_DEPTH) != 0) { if ((context.nodes() & SimpleOpenNI.NODE_IMAGE) != 0) { image(context.depthImage(), 0, 0); image(context.rgbImage(), context.depthWidth() + 10, 0); } else image(context.depthImage(), 0, 0); } if ((context.nodes() & SimpleOpenNI.NODE_SCENE) != 0) image(context.sceneImage(), 0, 0, context.sceneWidth()*.4, context.sceneHeight()*.4); // draw the context2 data if ((context2.nodes() & SimpleOpenNI.NODE_DEPTH) != 0) { if ((context2.nodes() & SimpleOpenNI.NODE_IMAGE) != 0) { image(context2.depthImage(), 0, context.depthHeight()); image(context2.rgbImage(), context2.depthWidth() + 10, context.depthHeight()); } else image(context2.depthImage(), 0, context.depthHeight()); } if ((context2.nodes() & SimpleOpenNI.NODE_SCENE) != 0) image(context2.sceneImage(), 0, context.depthHeight(), context2.sceneWidth()*.4, context2.sceneHeight()*.4); // draw timeline drawTimeline(); } void drawTimeline() { pushStyle(); stroke(255, 255, 0); line(10, height - 20, width -10, height - 20); stroke(0); rectMode(CENTER); fill(255, 255, 0); int pos = (int)((width - 2 * 10) * (float)context.curFramePlayer() / (float)context.framesPlayer()); rect(pos, height - 20, 7, 17); popStyle(); } void keyPressed() { switch(key) { case CODED: switch(keyCode) { case LEFT: // jump back context.seekPlayer(-3, SimpleOpenNI.PLAYER_SEEK_CUR); context2.seekPlayer(-3, SimpleOpenNI.PLAYER_SEEK_CUR); break; case RIGHT: // jump forward context.seekPlayer(3, SimpleOpenNI.PLAYER_SEEK_CUR); context2.seekPlayer(3, SimpleOpenNI.PLAYER_SEEK_CUR); break; case UP: // slow down context.setPlaybackSpeedPlayer(context.playbackSpeedPlayer() * 2.0f); context2.setPlaybackSpeedPlayer(context2.playbackSpeedPlayer() * 2.0f); println("playbackSpeedPlayer: " + context.playbackSpeedPlayer()); break; case DOWN: // speed up context.setPlaybackSpeedPlayer(context.playbackSpeedPlayer() * 0.5f); context2.setPlaybackSpeedPlayer(context2.playbackSpeedPlayer() * 0.5f); println("playbackSpeedPlayer: " + context.playbackSpeedPlayer()); break; } break; case ' ': // toggle pause context.setRepeatPlayer(!context.repeatPlayer()); context2.setRepeatPlayer(!context2.repeatPlayer()); println("RepeatMode: " + context.repeatPlayer()); break; case BACKSPACE: // restart context.seekPlayer(0, SimpleOpenNI.PLAYER_SEEK_SET); context2.seekPlayer(0, SimpleOpenNI.PLAYER_SEEK_SET); break; } }