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.
IndexProgramming Questions & HelpVideo Capture,  Movie Playback,  Vision Libraries › turn the frame differencing becomes transparent
Page Index Toggle Pages: 1
turn the frame differencing becomes transparent? (Read 373 times)
turn the frame differencing becomes transparent?
Apr 17th, 2010, 8:36am
 
I want to make the pixels of frame differencing becomes transparent. The following program can turn the pixels with differencing become red in color. I want to turn it into transparent, so that I can see another image imgBG covered by this theMov.image(), how can I do this? I want do something when tracking people move, the part of pixels can become transparent, and see the imgBG. Please help.


PImage imgBG;
import JMyron.*;

JMyron theMov;
int[] currFrame;
int[] prevFrame;
int tolerance;
boolean revealing;


void setup() {
 size(640, 480);
imgBG = loadImage("2.jpg");
 theMov = new JMyron();
 theMov.start(width, height);
 theMov.findGlobs(0);
 
 // initialize the pixel arrays to avoid a NullPointerException
 loadPixels();
 currFrame = prevFrame = pixels;

 tolerance = 40;  
 revealing = true;
 
 
}

void draw() {
image(imgBG,0,0);  
 background(0);

 theMov.update();
 // save the last frame before updating it
 prevFrame = currFrame;
 currFrame = theMov.image();

 // draw each pixel to the screen only if its change factor is
 // higher than the tolerance value
 
 float r,g,b;
 loadPixels();
 for (int i=0; i < width*height; i++) {
   if (comparePixels(i)) {

     //pixels[i] = currFrame[i];
     pixels[i] = color(255,0,0);
     
   }
 }
 updatePixels();
}

boolean comparePixels(int index) {
 if (Math.abs(red(currFrame[index])-red(prevFrame[index])) < tolerance)
   if (Math.abs(green(currFrame[index])-green(prevFrame[index])) < tolerance)
     if (Math.abs(blue(currFrame[index])-blue(prevFrame[index])) < tolerance)
       return !revealing;

 return revealing;
}

void keyReleased() {
 if (key == '.' || key == '>') {
   // increase tolerance
   tolerance += 2;
 } else if (key == ',' || key == '<') {
   // decrease tolerance
   tolerance -= 2;

 // toggle the revealing mode
 } else if (key == ' ') {
   revealing = !revealing;
 }
}

public void stop() {
 theMov.stop();
 super.stop();
}
Page Index Toggle Pages: 1