import processing.video.*; Capture cam; PImage back; // background image PImage fore; // foreground image float tolerance = 75; // our color tolerance void setup() { size(640,480); smooth(); cam = new Capture(this,640,480); cam.start(); back = new PImage(cam.width,cam.height); back.loadPixels(); fore = new PImage(cam.width,cam.height); } void draw() { if (cam.available()) { cam.read(); cam.loadPixels(); // pick a different selected color, if you want if(keyPressed && key== ' ') { back.copy(cam,0,0,cam.width,cam.height,0,0,cam.width,cam.height); back.loadPixels(); } // create an image of the foreground that is transparent where the background is visible for(int y = 0; y < cam.height; y ++) { for(int x = 0; x < cam.width; x ++) { color c1 = cam.pixels[x+y*cam.width]; color c2 = back.pixels[x+y*back.width]; float d = dist(red(c1),green(c1),blue(c1),red(c2),green(c2),blue(c2)); if(d < tolerance) fore.pixels[x+y*fore.width] = color(0); else fore.pixels[x+y*fore.width] = c1; } } fore.updatePixels(); // draw the image and the color //image(cam,0,0); image(fore,0,0); } } // START NO NOTES // code used to capture screenshots void keyReleased() { if(key == '`' && !online) save("sketch.png"); }