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 › create green background / moving person
Page Index Toggle Pages: 1
create green background / moving person (Read 585 times)
create green background / moving person
May 22nd, 2009, 4:08am
 
I want to capture the webcam video and make the background green, and the moving person, eh, not. I tried this, but it gives me a green window.

Code:

import processing.video.*;
Capture myCapture;
PImage lastCapture, curCapture;

void setup()
{
 size(200, 200);

 // The name of the capture device is dependent those
 // plugged into the computer. To get a list of the
 // choices, uncomment the following line
 //println(Capture.list());
 // And to specify the camera, replace "Camera Name"
 // in the next line with one from Capture.list()
 myCapture = new Capture(this, width, height, "ManyCam Virtual Webcam-WDM", 30);
}

void captureEvent(Capture myCapture) {
 // read webcam input
 myCapture.read();
}

void draw() {  
 //myCapture.read();
 myCapture.loadPixels();

 // save image for later use
 //curCapture = myCapture.pixels;
 curCapture = lastCapture;
 lastCapture = myCapture;

 // green = RGB 0,255,0
 color green = color(0,255,0);

 if(curCapture!=null){
   // for every pixel in myCapture
   for (int i = 0; i < myCapture.pixels.length; i++) {
     // if myCapture pixel i is same color as current-last capture pixel i
     if(myCapture.pixels[i] == curCapture.pixels[i]){
       // mycapture pixel i is green
       myCapture.pixels[i] = green;
     }
   }
 }
 
 myCapture.updatePixels();
 
 image(myCapture, 0, 0);
}


Re: create green background / moving person
Reply #1 - May 22nd, 2009, 4:30am
 
i read it quickly, but i have the feeling you'd better draw your greened image on a separate PImage, so that you'll be checking for movement always on clean frames.
Page Index Toggle Pages: 1