I've been using copy() and pixels a lot with images in memory. I can't make head nor tail of the new functions though. I don't know if I'm supposed to be using loadPixels on a PImage or from where I'm calling copy().
The idea is simple, I measure the difference between one frame and the next. I've added a bit of fade to it as I'm still working on it but I've ground to a halt trying to figure out p85 syntax.
Old Code:
Code:
boolean newFrame = false;
BImage swap;
BImage display;
BGraphics buf;
void setup() {
size(320, 240);
swap = loadImage("a.gif");
display = swap.copy();
background(255);
beginVideo(320, 240, 12);
}
void videoEvent() {
newFrame = true;
}
void loop() {
//background(display);
if(newFrame) {
// noStroke();
fill(255,255,255,30);
rect(0,0,width,height);
difference();
newFrame = false;
swap = video.copy();
}
}
void difference(){
for (int iy = 0; iy < video.height; iy++){
for (int ix = 0; ix < video.width; ix++){
color c1 = video.pixels[ix + iy * video.width];
color c2 = swap.pixels[ix + iy * swap.width];
int r1=c1>>16&0xff;
int g1=c1>>8&0xff;
int b1=c1&0xff;
int r2=c2>>16&0xff;
int g2=c2>>8&0xff;
int b2=c2&0xff;
//display.pixels[ix + iy * display.width] = color (255-abs(r1-r2),255-abs(g1-g2),255-abs(b1-b2), 50);
if (abs(r1-r2) > 0 && abs(g1-g2) > 0 && abs(b1-b2) > 0){
stroke(color (255-abs(r1-r2),255-abs(g1-g2),255-abs(b1-b2), 50));
point(ix,iy);
}
}
}
}
New, and still not working code:
Code:
import processing.video.*;
Capture myCapture;
PImage swap;
PImage display;
void setup() {
size(320, 240);
String s = "Creative WebCam Live! Pro-WDM";
myCapture = new Capture(this, s, width, height, 12);
swap = loadImage("a.gif");
display = loadImage("a.gif");//.copy(swap,0,0,swap.width,swap.height,0,0,swap.width,swap.height);
//still can't figure out copy()
background(255);
}
void captureEvent(Capture myCapture) {
myCapture.read();
}
void draw() {
fill(255,255,255,30);
rect(0,0,width,height);
difference();
swap.copy(myCapture,0,0,myCapture.width,myCapture.height,0,0,swap.width,swap.height);
image(display, 0, 0);
}
void difference(){
for (int iy = 0; iy < myCapture.height; iy++){
for (int ix = 0; ix < myCapture.width; ix++){
color c1 = myCapture.pixels[ix + iy * myCapture.width];
color c2 = swap.pixels[ix + iy * swap.width];
int r1=c1>>16&0xff;
int g1=c1>>8&0xff;
int b1=c1&0xff;
int r2=c2>>16&0xff;
int g2=c2>>8&0xff;
int b2=c2&0xff;
//display.pixels[ix + iy * display.width] = color (255-abs(r1-r2),255-abs(g1-g2),255-abs(b1-b2), 50);
if (abs(r1-r2) > 0 && abs(g1-g2) > 0 && abs(b1-b2) > 0){
stroke(color (255-abs(r1-r2),255-abs(g1-g2),255-abs(b1-b2), 50));
point(ix,iy);
}
}
}
}
Could somebody set me straight please?