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 & HelpPrograms › interactive Mosaic Mirror
Page Index Toggle Pages: 1
interactive Mosaic Mirror (Read 863 times)
interactive Mosaic Mirror
Feb 17th, 2010, 9:57am
 

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...

Code:
// 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);

}
}
}
Re: interactive Mosaic Mirror
Reply #1 - Feb 17th, 2010, 10:56am
 
You could have those certain images binded to certain brightnesses. If you wanted it to be able to process any image file you would have to make it load it then have processing check the "average" brightness of the file then use it in accordance with the video feed to be displayed. Thats how i would do it anywas.
Re: interactive Mosaic Mirror
Reply #2 - Mar 6th, 2010, 1:05pm
 
Yeah I thought my best bet would be binding certain images to set brightness values, but i have no idea how i would go about doing so.

I have tired a basic if statement, but no luck yet.
Any ideas?
Page Index Toggle Pages: 1