We are about to switch to a new forum software. Until then we have removed the registration on this forum.
This is the default renderer:
This is in OpenGL:
When i move the mouse i'm supposed to only change the image on the right. In OpenGl it affects both. Why is this? It makes no sense to me at all.
Then if i press 'b' it sets a new background. But for some reason it never updates the image, it keeps the background i set first. Why is that?
import SimpleOpenNI.*;
SimpleOpenNI context;
color white = color(255);
color black = color(0);
PGraphics pg, background;
void setup() {
size(1024, 768, OPENGL);
context = new SimpleOpenNI(this);
if(!context.enableDepth())println("problem with kinect");
pg = createGraphics(context.depthImage().width, context.depthImage().height, JAVA2D);
background = createGraphics(context.depthImage().width, context.depthImage().height, JAVA2D);
background.loadPixels();
pg.loadPixels();
}
// . . . . . . . . . . . . . . . . . . . . . . . .
void draw() {
// update the cam
context.update();
pg.beginDraw();
pg.image(context.depthImage(), 0, 0);
pg.endDraw();
// pg.updatePixels();
background(0);
//translate(-context.depthImage().width/2, -context.depthImage().height/2);
image(pg, 0, 0, pg.width/2, pg.height/2);
fill(255);
text("pg before subtract", 0, -20);
pg.loadPixels();
subtract(background.pixels, pg.pixels);
pg.updatePixels();
text("pg after subtract", pg.width, -20);
image(pg, pg.width/2, 0, pg.width/2, pg.height/2);
text("background", pg.width*2, -20);
image(background, 0, pg.height/2, pg.width/2, pg.height/2);
}
// . . . . . . . . . . . . . . . . . . . . . . . .
void keyPressed() {
if (key == 'b') {
createBackground();
}
}
void createBackground() {
println("createBackground");
background.beginDraw();
background.image(context.depthImage(), 0, 0);
background.endDraw();
background.loadPixels();
}
void subtract(int[] pixelsA, int[] pixelsB) {
float r, g, b;
float r2, g2, b2;
for (int i = 0; i < pixelsA.length; i++) {
r = red(pixelsA[i]);
g = green(pixelsA[i]);
b = blue(pixelsA[i]);
r2 = red(pixelsB[i]);
g2 = green(pixelsB[i]);
b2 = blue(pixelsB[i]);
//pixelsB[i] = color(abs(r-r2), abs(g-g2), abs(b-b2));
float t = map(mouseX, 0, width, 0, 255);
pixelsB[i] = abs(r-r2) > t || abs(g-g2) > t || abs(b-b2) > t ? white : pixelsB[i];
}
}