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.
Page Index Toggle Pages: 1
live capture as sensor (Read 1061 times)
live capture as sensor
Oct 24th, 2005, 11:42pm
 
I am trying to read pixels that are skin color from a live video capture and convert them to pixels of a quicktime movie so that all that would be visible in the window is the quicktime movie playing in the areas where skin appears in the live captured video, every other pixel on the screen would be black. Unfortunately it is not working very well. here is the code- any ideas?


import processing.video.*;
Movie myMovie;
Capture myCapture;
float redLower = .55f;
float redUpper = .75f;
float greenLower = .45f;
float greenUpper = .55f;

void setup()
{
 size(320,240);
 myMovie = new Movie (this, "source2.mov");
 noStroke();
 background(0);
 myMovie.loop();
 // println(Capture.list());
 String s = "DV Video";
 myCapture = new Capture (this,  width, height, 30);
 framerate(10);
}
void captureEvent (Capture myCapture) {
 myCapture.read();
}

void movieEvent (Movie mymovie){
 myMovie.read();
}

void draw()
{

 loadPixels();
 
   for(int i =0; i < myCapture.pixels.length; i++){
     int thisPixel = myCapture.pixels[i];
     //trade in rbb for a percentage red and percentage green so
     //brightness falls out of it
     float total = red(thisPixel) + green(thisPixel) + blue(thisPixel);
     float normalizedRed =  red(thisPixel)/total;
     float normalizedGreen = green(thisPixel)/total;

     if (normalizedRed < redUpper && normalizedRed > redLower &&
       normalizedGreen < greenUpper && normalizedGreen > greenLower){

       //if (thisPixel is skin colored) {
       //use the movie pixel for this pixel
       myCapture.pixels[i] = myMovie.pixels[i];

     }
     else{
       //make it black
       myCapture.pixels[i] = color(0);
     }
   }


   updatePixels();
image(myCapture,0,0);
 
 }
 void keyPressed(){  //conviences for changing variables while you are the
   //applet is running
   //different cameras will need different numbers
   if (keyCode ==38) { //up arrow
     redUpper = redUpper + .01f;
     redLower = redLower + .01f;
   }
   else if(keyCode == 40){ //down arrow
     redUpper = redUpper - .01f;
     redLower = redLower - .01f;
   }
   else if (keyCode ==37) { //up arrow
     greenUpper = greenUpper + .01f;
     greenLower = greenLower + .01f;
   }
   else if(keyCode == 39){ //down arrow
     greenUpper = greenUpper - .01f;
     greenLower = greenLower - .01f;
   }
   println("key: " + keyCode  );
 }

Re: live capture as sensor
Reply #1 - Oct 25th, 2005, 12:41am
 
Without seeing the output, its hard to figure out what needs to be tuned.

Cant you just very simply copy all the pixels you want of the movie to a black image every frame?

Should be rather straighforward.
Re: live capture as sensor
Reply #2 - Oct 25th, 2005, 2:33am
 
I'm actually new to processing, which is part of the problem. I managed to figure out which pixels are skin in the video capture and I thought I was transfering those pixels to the pixels in the movie by saying myCapture.pixels[i] = myMovie.pixels[i] but then nothing comes up on the screen. So I added image(myCapture,0,0), but all that does is capture the live video and then every once and a while flicker to a black screen with white dots, like its trying to play the movie in the specified pixels but not quite.
Re: live capture as sensor
Reply #3 - Oct 26th, 2005, 4:21am
 
be careful when doing this kind of work about the driver settings for your camera. Most webcams have auto white balancing and auto exposure etc. On Logitech camera's you can turn this off in the driver settings (or at least you can in my quickcam 4000 pro).

If you don't do this when the volume of the screen occupied by one colour changes it balances the image to try and rectify which can throw calculations off.
Page Index Toggle Pages: 1