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 & HelpPrograms › Brightness Tracking
Page Index Toggle Pages: 1
Brightness Tracking (Read 488 times)
Brightness Tracking
Jan 20th, 2008, 11:20pm
 
Hey Guys.

I'm pretty new to processing and I'm trying to change the light tracking example in a way that it shows a circle on top of all pixels with the brightness of lets say more than 100.

I kina know that I have to put the pixels into an array but Ive been messing with it for couple of days and its not going anywhere. any help with be appriciated.

here is the example which shows only one circle on the brightest spot.

thanks
Loki



import processing.video.*;

Capture video;

void setup() {
 size(640, 480); // Change size to 320 x 240 if too slow at 640 x 480
 // Uses the default video input, see the reference if this causes an error
 video = new Capture(this, width, height, 30);
 noStroke();
 smooth();
}

void draw() {
 if (video.available()) {
   video.read();
   image(video, 0, 0, width, height); // Draw the webcam video onto the screen
   int brightestX = 0; // X-coordinate of the brightest video pixel
   int brightestY = 0; // Y-coordinate of the brightest video pixel
   float brightestValue = 0; // Brightness of the brightest video pixel
   // Search for the brightest pixel: For each row of pixels in the video image and
   // for each pixel in the yth row, compute each pixel's index in the video
   video.loadPixels();
   int index = 0;
   for (int y = 0; y < video.height; y++) {
     for (int x = 0; x < video.width; x++) {
       // Get the color stored in the pixel
       int pixelValue = video.pixels[index];
       // Determine the brightness of the pixel
       float pixelBrightness = brightness(pixelValue);
       // If that value is brighter than any previous, then store the
       // brightness of that pixel, as well as its (x,y) location
       if (pixelBrightness > brightestValue) {
         brightestValue = pixelBrightness;
         brightestY = y;
         brightestX = x;
       }
       index++;
     }
   }
   // Draw a large, yellow circle at the brightest pixel
   fill(255, 204, 0, 128);
   ellipse(brightestX, brightestY, 200, 200);
 }
}
Re: Brightness Tracking
Reply #1 - Jan 21st, 2008, 2:02am
 
If all you want is a circle on each pixel brighter than 50, you don't really need an array for that.

In the code, where it checks the brightness with this line:
if (pixelBrightness > brightestValue) {

you can change the IF statement to see if it's brighter than 50
if (pixelBrightness > 50) {

and inside just draw an ellipse at the x & y coords.

if (pixelBrightness > 50) {
   ellipse(x,y,10,10);
  }


that should do it, unless i missread your question.
Re: Brightness Tracking
Reply #2 - Jan 21st, 2008, 6:22pm
 
thanks for the tip man.
It worked and it was easy. the downside however is that
1.it made me feel like an idiot for not thinking of it.
2. its toooo slow.

Im sure you cant help me with the first one but any suggestions for its slowness???
thanks
Loki
Page Index Toggle Pages: 1