second attempt with SimpleOpenNI - unsuccessfully
- import processing.opengl.*;
- import codeanticode.glgraphics.*;
- import SimpleOpenNI.*;
- GLTexture bottomLayer, topLayer, resultLayer;
- GLTextureFilter blendFilter;
- ScalarParam opacity;
- SimpleOpenNI context;
- PImage img;
- void setup()
- {
- size(640, 480, GLConstants.GLGRAPHICS);
- context = new SimpleOpenNI(this);
- // mirror is by default enabled
- context.setMirror(true);
- //context.enableRGB(640,480,30);
- //context.enableRGB(1280,1024,15);
- if(context.enableRGB() == false)
- {
- println("Can't open the rgbMap, maybe the camera is not connected or there is no rgbSensor!");
- exit();
- return;
- }
- blendFilter = new GLTextureFilter(this, "BlendDifference.xml");
- opacity = new ScalarParam(1.0,0.0,1.0,0.01);
- bottomLayer = new GLTexture(this, "background.jpg");
- topLayer = new GLTexture(this);
- resultLayer = new GLTexture(this, topLayer.width,topLayer.height);
- }
- void draw()
- {
- background(0);
- noStroke();
- context.update();
- img = context.rgbImage();
- topLayer.putImage(img);
- blendFilter.setParameterValue("Opacity", opacity.value);
- blendFilter.apply(new GLTexture[] {bottomLayer, topLayer}, resultLayer);
- resultLayer.render(0, 0);
- println(frameRate);
- }
- void keyPressed()
- {
- if (key == CODED) {
- if (keyCode == UP) opacity.Increment();
- else if (keyCode == DOWN) opacity.Decrement();
- }
- }
- class ScalarParam {
- float value;
- float minValue;
- float maxValue;
- float step;
- ScalarParam(float v,float mn, float mx, float s) {
- value = v;
- minValue = mn;
- maxValue = mx;
- step = s;
- }
- void Increment() {
- value += step;
- if (value > maxValue) value=maxValue;
- }
- void Decrement() {
- value -= step;
- if (value < minValue) value=minValue;
- }
- }