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 › Video processing!
Page Index Toggle Pages: 1
Video processing! (Read 575 times)
Video processing!
Apr 8th, 2010, 8:33am
 
hi guys
i was wondering if someone can help me with this piece of code... it is to track the brightest pixel in a video image but i need it to track the darkest pixel but i'm pretty new to coding and it's not working out to well. if you guys have any suggestions the would be greatly appreciated
thanks Stu

have a look

/**
* Brightness Tracking
* by Golan Levin.
*
* Tracks the brightest pixel in a live video signal.
*/
/**
* all i have done to this code is invert the image so
* that the bright aeras turn dark, i wanr to do this
* as the user will be casting a shadow on the the surface
* and i wanted this to appear as the lightest part of the image.
*
* By Stuart Blows
*/

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();
   //video.filter(INVERT); // makes the light in the image inverted
   image(video, 0, 0, width, height); // Draw the webcam video onto the screen
   int brightestX = 255; // X-coordinate of the brightest video pixel
   int brightestY = 255; // 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(000, 000, 000, 500);
   ellipse(brightestX, brightestY, 20, 20);
 }
 
}
Re: Video processing!
Reply #1 - Apr 8th, 2010, 5:22pm
 
I spose you could go either way:

1. skip the video.filter(INVERT); thing
2. Test for lower pixelBrightness instead of higher:
   if (pixelBrightness < darkestValue) { ( as you can see I changed the name of the brightestValue variable so the rest should be changed as well for clarity. Or you can just go with brightestValue and just flip the >)
Page Index Toggle Pages: 1