Bu Blogda Ara

29 Aralık 2009 Salı

üçüncü renk mavidir

/**
* Brightness Tracking
* by Golan Levin.
*
* Tracks the brightest pixel in a live video signal.
* revision by Çağrı Hakan Zaman 20 Aralik 2009
* revision by Sema Alaçam 29 Aralik 2009
*/

import processing.video.*;
Capture video;

String[] alist = new String[100];

void setup() {
size(600, 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();
frameRate(4);
}

void draw() {

if (video.available()) {
video.read();
//image(video, 0, 0, width, height); // Draw the webcam video onto the screen
int brightestX = width/2; // X-coordinate of the brightest video pixel
int brightestY = width/2; // Y-coordinate of the brightest video pixel
int redX = width/2;
int redY = width/2;
int blueX = width/2;
int blueY = width/2;
float blueeValue = 128;
float brightestValue =128;
float reddValue = 128;
// 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 redValue = red(pixelValue);
float greenValue= green(pixelValue);
float blueValue= blue(pixelValue);

// If that value is brighter than any previous, then store the
// brightness of that pixel, as well as its (x,y) location
if ((greenValue > 140)&&(redValue>140)&&(blueValue<60)){
if (( x !=0) &&( y != 0))
{
brightestValue = redValue;
brightestY = y;
brightestX = x;
}
}

if ((blueValue> 200)&&(greenValue < 150)&&(redValue< 200)){
if (( x !=0) && (y != 0)){
blueeValue = blueValue;
blueY = y;
blueX = x;
}
}
if ((redValue > reddValue)&&(blueValue<90)&&(greenValue<90)){
if (( x !=0) &&( y != 0))
{
reddValue = redValue;
redY = y;
redX = x;
}
}
index++;
}
}
// Draw a large, yellow circle at the brightest pixel

fill(255, 204, 0, 128);
ellipse(brightestX, brightestY, 14, 14);
stroke(0,0,0,120);

fill (255, 0, 0 , 128);
ellipse(redX,redY, 14,14);
fill (0, 50, 200 , 128);
ellipse(blueX,blueY, 14,14);



line(blueX, blueY, brightestX, brightestY);
line(redX, redY, blueX, blueY);
line(brightestX, brightestY, redX, redY);

}
}

Hiç yorum yok:

Yorum Gönder