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 › load image(s) based on brightness of video pixels
Page Index Toggle Pages: 1
load image(s) based on brightness of video pixels (Read 957 times)
load image(s) based on brightness of video pixels
Mar 20th, 2007, 6:48pm
 
I'm not sure if I have this question worded correctly but...

I have a live video feed and I am animating an array of images based on the brightness of the pixels from live video.

I've seen this done before.  Not sure who did it and didn't know how it was achieved so this was my first guess.

I'm trying to figure out how to smooth out the animation.
I can post the image sequence to a website if anyone wants them.

I haven't cleaned up my code but here it is.

PS... I'm a total hack at coding and I love Processing!!!

import processing.opengl.*;
import processing.video.*;

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


int numFrames = 99;  // The number of frames in the animation
int frame = 0;
int framenum;
PImage[] images = new PImage[numFrames];

void setup()
{
 size(800,600,OPENGL);//could be P3D but OPENGL is smoother
 frameRate(30);
 //set up columns and rows
 cols = width/cellsize;
 rows = height/cellsize;
 colorMode(RGB,255,255,255,50);
 

 // Using the default capture device
 video = new Capture(this, 800, 600, 30);

//loading all the frames of the flower
for(int i=0; i<numFrames; i++) {
 String imageName = "flower_" + ((i < 99) ? "0" : "") + i + ".png";
 images[i] = loadImage(imageName);
}
 background(0);

}

void captureEvent(Capture camera)
{
 camera.read();
}

//void movieEvent(Movie myMovie) {
//  myMovie.read();
//}


void draw()
{  
 background(50,50,150);

 // 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*cellsize;
  int y = j*cellsize;
 
 
 int loc = (video.width - x - 1) + y*video.width;
 // Get RGB values from image
 float r = red(video.pixels[loc]);
 float g = green(video.pixels[loc]);
 float b = blue(video.pixels[loc]);
float sz = (brightness(video.pixels[loc])/128.0f)*(cellsize*3);


tint(r,g,b, sz);
 
//make sure sz doesn't go over 99 frames  
if (sz >= 98){
   frame = 98;
   }else{
   frame = int(sz);
   }

 image(images[frame], x, y);

}
 }
}
Re: load image(s) based on brightness of video pixels
Reply #1 - Mar 6th, 2010, 1:00pm
 
Hey, I am now trying to do a similar things, did you ever have any luck?
Page Index Toggle Pages: 1