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 › Make the pixels become transparent. Please Help!
Page Index Toggle Pages: 1
Make the pixels become transparent. Please Help! (Read 406 times)
Make the pixels become transparent. Please Help!
Apr 18th, 2010, 5:31am
 
Below is a mirrored frame differencing program. And the pixels with changes will become red. I want to change the pixels (in red now) to become transparent. How to do it? Please help..


import processing.video.*;

int numPixels;
int[] previousFrame;
Capture video;


void setup() {
 size(320, 240);
 video = new Capture(this, width, height, 24);
 video.format = ARGB;
 numPixels = video.width * video.height;
 // Create an array to store the previously captured frame
 previousFrame = new int[numPixels];
 loadPixels();
 
}

void draw() {
 if (video.available()) {
   video.read();
   video.loadPixels();
   
   //Reversing x to mirror the image
    int index = 0;
 for (int y=0; y<video.height; y++) {
   for (int x=0; x<video.width; x++) {
     pixels[index + video.width - x - 1] = video.pixels[index + x];
   }
   index += video.width;
 }

 
   int movementSum = 0;
   for (int i = 0; i < numPixels; i++) {
     color currColor = pixels[i];
     color prevColor = previousFrame[i];
     
     int currR = (currColor >> 16) & 0xFF;
     int currG = (currColor >> 8) & 0xFF;
     int currB = currColor & 0xFF;
     
     int prevR = (prevColor >> 16) & 0xFF;
     int prevG = (prevColor >> 8) & 0xFF;
     int prevB = prevColor & 0xFF;

     int diffR = abs(currR - prevR);
     int diffG = abs(currG - prevG);
     int diffB = abs(currB - prevB);
   
     movementSum += diffR + diffG + diffB;
     
    // pixels[i] = color(diffR, diffG, diffB);
    pixels[i] = color(diffR, 0,0,100);

     previousFrame[i] = currColor;

 }

   if (movementSum > 0) {
     updatePixels();
     println(movementSum);
   }
 }
}
Page Index Toggle Pages: 1