/** * Brightness Tracking * by Golan Levin. * * Tracks the brightest pixel in a live video signal. */ import processing.video.*; Capture video; int threshold = 225 ; int pixelSize = 1 ; 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(); fill(0, 0, 0, 255); rect(0, 0, width, height) ; } void draw() { if (video.available()) { video.read(); // image(video, 0, 0, width, height); // Draw the webcam video onto the screen 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 color currColor = video.pixels[index]; int pixelValue = video.pixels[index]; float pixelBrightness = brightness(pixelValue); if( pixelBrightness > threshold ) { int currR = (currColor >> 16) & 0xFF; // Like red(), but faster int currG = (currColor >> 8) & 0xFF; int currB = currColor & 0xFF; fill(currR, currG, currB, pixelBrightness); ellipse(x - (pixelSize/2) , y - (pixelSize/2), pixelSize, pixelSize); } index++; } } } }