We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
compare 2 images from one vid feed (Read 943 times)
compare 2 images from one vid feed
Sep 17th, 2005, 9:44pm
 
hi all

i have some code that is meant to save and draw an image from a cam as bg, then draw pixelated versions of anything that moves through the bg on top of it ( so people walking through a space would look censored for example). the prob i seem to have is that both my matrices 'bg' and 'in' which come from the same cam are always the same. even though bg should only be updated when a key is pressed. i have had no luck opening 2 capture objects from the same cam or just copying the feed into the bg image with bg = in; i think the answer might be in copying the array as mentioned here:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=VideoCamera;action=display;num=1123580926

but i'm not sure how to implement this.

any help would be greatly appreciated - here's my code:

****************************

import processing.video.*;
Capture myCapture;
PImage bg;
PImage in;
//distance on colour for section to be pixelated
float thresh = 13;
//size of each rect
int cellsize = 8;
//number of columns and rows in our system
int COLS, ROWS;

void setup()
{
 size(320, 240);
 framerate(12);
 COLS = width/cellsize;
 ROWS = height/cellsize;
 //colorMode(RGB,255,255,255,100);
 rectMode(CENTER);
 noStroke();
 
 //println(Capture.list());
 String s = "DV Video";
 myCapture = new Capture(this, s, width, height, 12);
 
 myCapture.read();
 bg = myCapture;
 
}

void draw()
{
 image(bg,0,0); //draws bg from keypress
 pixelate();

}

void pixelate() {

 myCapture.read();
 in = myCapture;

 //begin loop for columns
 for ( int i = 0; i < COLS;i++) {
   //begin loop for rows
   for ( int j = 0; j < ROWS;j++) {
     //save transformation matrix
     pushMatrix();
     //calculate x and y location
     int x = i*cellsize + cellsize/2;
     int y = j*cellsize + cellsize/2;
     int loc = x + y*width;
     loc = constrain(loc,0,in.pixels.length-1);
     //get colours from feed
     float R2 = red(in.pixels[loc]);
     float G2 = green(in.pixels[loc]);
     float B2 = blue(in.pixels[loc]);
     //get colours from bg
     float R1 = red(bg.pixels[loc]);
     float G1 = green(bg.pixels[loc]);
     float B1 = blue(bg.pixels[loc]);
     
     translate(x,y);      
     float d = dist(R2,G2,B2,R1,G1,B1);

     if ( d > thresh ) {
     //draw rect:
     fill(R2,G2,B2);
     rect(0,0,cellsize,cellsize);  
     }
     //restore transformation matrix
     popMatrix();
   }
 }
}


void keyPressed() {
 myCapture.read();
 bg = myCapture;
 println("new bg");
}
Re: compare 2 images from one vid feed
Reply #1 - Sep 18th, 2005, 3:25am
 
sorry, missed this thread before:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=VideoCamera;action=display;num=1117150396

got it to work with:
 bg = new PImage(width,height);
 for (int i=0;i<width*height; i++){
   bg.pixels[i] = in.pixels[i];
 }

cheers.
Page Index Toggle Pages: 1