/** * Brightness Tracking * by Golan Levin. * * Tracks the brightest pixel in a live video signal. */ import processing.video.*; Capture video; int upper, lower, left, right; 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 println(Capture.list()); // video = new Capture(this, width, height, "Sony HD Eye for PS3 (SLEH 00201)", 30); video = new Capture(this, width, height, 30); noStroke(); smooth(); upper=left=0; lower=height; right=width; } void draw() { if (video.available()) { video.read(); image(video, 0, 0, width, height); // Draw the webcam video onto the screen int reddestX = 0; // X-coordinate of the brightest video pixel int reddestY = 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 = upper; y < lower; y++) { for (int x = left; x < right; x++) { index = x + y * video.width; // Get the color stored in the pixel int pixelValue = video.pixels[index]; // Determine the brightness of the pixel float pixelBrightness = red(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; reddestY = y; reddestX = x; } // index++; } } // Draw a large, yellow circle at the brightest pixel fill(255, 0, 0, 128); if(brightestValue > 192) ellipse(reddestX, reddestY, 20, 20); } stroke(128, 0, 0); noFill(); rect(left, upper, right-left, lower-upper); noStroke(); } void mousePressed() { upper=mouseY; left=mouseX; } void mouseDragged() { lower=mouseY; right=mouseX; } void mouseReleased() { lower=mouseY; right=mouseX; if(upper>lower) { int temp=upper; upper=lower; lower=temp; } if(right