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 & HelpVideo Capture,  Movie Playback,  Vision Libraries › inputing images depending on brightness
Page Index Toggle Pages: 1
inputing images depending on brightness (Read 440 times)
inputing images depending on brightness
Jan 19th, 2010, 7:09am
 
I am currently working on an interactive mosaic mirror.

At the moment i have the code, taking in the live video feed and detecting the light and dark sections of the capture. and displaying large squares for light and smaller squares for dark.

I am now intrested in replacing these squares with images from a selected folder. Dose anyone have any advice and ideas on how i would go about this.

Thanks.

Code so far...

// interactive miror

// Each pixel from the video source is drawn as a
// rectangle with size based on brightness.

import processing.video.*;

// Size of each cell in the grid
int videoScale =10;
// Number of columns and rows in our system
int cols, rows;
// Variable for capture device
Capture video;

void setup() {
 size(740,580);
 // Initialize columns and rows
 cols = width/videoScale;
 rows = height/videoScale;
 smooth();
 // Construct the Capture object
 video = new Capture(this,cols,rows,15);
}

void draw() {
 if (video.available()) {
   video.read();
 }
 background(0);

 video.loadPixels();

 // Begin loop for columns
 for (int i = 0; i < cols; i++) {
   // Begin loop for rows
   for (int j = 0; j < rows; j++) {

     // Where are we, pixel-wise?
     int x = i*videoScale;
     int y = j*videoScale;

     // Reversing x to mirror the image
     // In order to mirror the image, the column is reversed with the following formula:
     // mirrored column = width - column - 1
     int loc = (video.width - i - 1) + j*video.width;

     // Each rect is colored white with a size determined by brightness
     color c = video.pixels[loc];

     // A rectangle size is calculated as a function of the pixel's brightness.
     // A bright pixel is a large rectangle, and a dark pixel is a small one.
     float sz = (brightness(c)/255.0)*videoScale;
     rectMode(CENTER);
     fill(255);
     noStroke();
     rect(x + videoScale/2,y + videoScale/2,sz,sz);

   }
 }
}
Page Index Toggle Pages: 1