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
2 points brightness tracking. How to??? (Read 505 times)
2 points brightness tracking. How to???
Feb 1st, 2009, 4:12pm
 
Hi all!
I'm a newbie on Processing and i'm trying to do this thing:
i've open the example call"Brightness Tracking", it  tracks the brightest pixel on the screen.

This is the code:

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);
 }
}

If i want to track 2 points, what is the way to follow?
Trying to use 2d arrays?


Cheers
Gio!
Re: 2 points brightness tracking. How to???
Reply #1 - Feb 3rd, 2009, 11:55am
 
standard multi zone tracking should do the trick:
a) filter binarily the entire screen for all pixels of brightness higher then a certain threshold value.
b) parse the whole screen to find conglomerates of brightness (id tag the adjacent pixels when you spot them)
c) ignore noise (conglomerates of just 1 or 2 pixels), you can also pre-filter it somehow
d) mark the screen centermass of each conglomerate to avoid reparsing the entire screen every frame (just search nearby pixels to where the conglomerate is)

if you dont know how to generate conglomerates, its not that hard:
when first reaching a pixel that should be part of a conglomerate but is not tagged yet: do a recursive clockwise pixel check. google up some example code.
Re: 2 points brightness tracking. How to???
Reply #2 - Feb 3rd, 2009, 2:00pm
 
Thanks a lot! I try to do this!
Re: 2 points brightness tracking. How to???
Reply #3 - Feb 3rd, 2009, 3:58pm
 
Only one question:
where can i find some tutorial for perform this tasks???


Thanks a lot PS!
Re: 2 points brightness tracking. How to???
Reply #4 - Feb 4th, 2009, 2:28pm
 
no bother

just google for computer vision source code. plenty of scientific papers available from open research groups involved in robotics and university teaching around, most of them usually have some tutorial example code about these computer vision basics.

also opencv sourcecode might be worth a look
http://opencv.willowgarage.com/wiki/
Page Index Toggle Pages: 1