as
YaBB Newbies
Offline
Posts: 30
Re: multiblob detector
Reply #1 - Jun 21st , 2008, 3:29am
void draw() { if (video.available()) { video.read(); // Read a new video frame video.loadPixels(); // Make the pixels of video available // Difference between the current frame and the stored background int presenceSum = 0; for (int i = 0; i < numPixels; i++) { // For each pixel in the video frame... // Fetch the current color in that location, and also the color // of the background in that spot color currColor = video.pixels[i]; color bkgdColor = backgroundPixels[i]; int currG = (currColor >> 8) & 0xFF; int bkgdG = (bkgdColor >> 8) & 0xFF; int diffG = abs(currG - bkgdG); presenceSum += diffG ; int binarize = (diffG > videothresh) ? 255 : 0; videotexbin.pixels[i] = 0xFF000000 | (binarize << 16) | (binarize << 8) | binarize; videotexgray.pixels[i] = 0xFF000000 | (diffG << 16) | (diffG << 8) | diffG; } println("presence "+presenceSum); // Print out the total amount of movement videotexbin.updatePixels(); ///notify videotex pixels changed videotexgray.updatePixels(); ///notify videotex pixels changed ///////CALC BLOBS blobs.calc(videotexbin); blobs.query(); // render textures float dimx = 160;//320; float dimy = 120;//240; // render textures gray pushMatrix(); translate(170, 300, 0); beginShape(); texture(videotexgray); vertex(-dimx,-dimy,0., 0, 0); // vertex(180,20, feed1size,0); vertex(dimx,-dimy,0., videores,0); vertex(dimx,dimy,0., videores,videores); vertex(-dimx,dimy,0., 0,videores); endShape(); popMatrix(); // render textures bin pushMatrix(); translate(500, 300, 0); beginShape(); texture(videotexbin); vertex(-dimx,-dimy,0., 0, 0); // vertex(180,20, feed1size,0); vertex(dimx,-dimy,0., videores,0); vertex(dimx,dimy,0., videores,videores); vertex(-dimx,dimy,0., 0,videores); endShape(); popMatrix(); } }