nay
YaBB Newbies
Offline
Posts: 22
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"); }