Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

RESTAR IMAGENES PROCESSING CÓDIGO

import processing.video.*;

Capture cam;
PImage fondo = new PImage (1280,720);
PImage resultado = new PImage (1280,720);
void setup() {
size(1280,720);

String[] cameras = Capture.list();

if (cameras == null) {
println("Failed to retrieve the list of available cameras, will try the default...");
cam = new Capture(this, 640, 480);
} if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
} else {
println("Available cameras:");
printArray(cameras);

cam = new Capture(this, cameras[0]);

cam.start();
}
}

void draw() {
if (cam.available() == true) {
cam.read();

cam.loadPixels();
fondo.loadPixels();
resultado.loadPixels();

int diferencia = 0;

for(int i=0; i < width * height; i++){


int r = int(red(cam.pixels[i]));
int g = int(green(cam.pixels[i]));
int b = int(blue(cam.pixels[i]));

int r2 = int(red(fondo.pixels[i]));
int g2 = int(green(fondo.pixels[i]));
int b2 = int(blue(fondo.pixels[i]));
diferencia = diferencia+ abs((r-r2)+(g-g2)+(b-g2));
resultado.pixels[i] = color(r-r2,g-g2,b-g2);
}
{
}
cam.updatePixels();
fondo.updatePixels();
resultado.updatePixels();

image(resultado, 0, 0, width, height);


}
}

void keyPressed(){
fondo.pixels = cam.pixels;
println("guardado");
}

You might also like