Hello! I'm pretty much a processing beginner but I've been working on this script that reads the pixels of a video file and draws a rectangle of the same color at a z height dependent on the pixel's brightness value. 2 questions for you processing masters out there: 1.) when drawing rectangles 1x1 pixels it skips frames and gets heavy. How can I make this script more efficient so as not to be so jerky. and 2.) the higher the size of the rectangle being drawn for each pixel, the more the frame of the video file is cut off. How can I rectify this so that I see the whole frame of the video no matter the size of the rectangle (named 'blocksize' in the script). The code has contributed libraries PeasyCam and GSVideo. Thank you in advance!!
import peasy.*;
import codeanticode.gsvideo.*;
PeasyCam cam;
int numPixels;
int blockSize = 1;
GSMovie myMovie;
color myMovieColors[];
void setup() {
size(800, 600, P3D);
frameRate(60);
noStroke();
rectMode(CENTER);
background(0);
myMovie = new GSMovie(this, "facade masked.mov"); // change movie file name here!!
myMovie.loop();
numPixels = width / blockSize;
myMovieColors = new color[numPixels * numPixels];
cam = new PeasyCam(this,width/2,height/2,0,1000);
}
// Read new values from movie
void movieEvent(GSMovie m) {
m.read();
m.loadPixels();
for (int j = 0; j < numPixels; j++) {
for (int i = 0; i < numPixels; i++) {
myMovieColors[j*numPixels + i] = m.get(i, j);
}
}
}
// Display values from movie
void draw() {
background(0);
for (int j = 0; j < numPixels; j++) {
for (int i = 0; i < numPixels; i++) {
pushMatrix();
float z = brightness(myMovieColors[j*numPixels + i]);
translate(i,j,z);
fill(myMovieColors[j*numPixels + i]);
if ( brightness(myMovieColors[j*numPixels + i]) < 220) {
rect(i, j, blockSize, blockSize);
}
popMatrix();
}
}
//saveFrame("facade-####.tif");
}
btw: code is based on Hernando Barragan's Pixelate.
I've been working on a script that takes video and extrudes each pixel based on brightness or color values. I've gotten it to work using GSCapture and my webcam but I cant get it to work on a quicktime movie. i've incorporated the PeasyCam library to be able to orbit around and zoom into the pixel cloud. So, i'm not sure where to insert the mov.read() and loadPixels() commands --- in draw or movieEvent? will that matter? For GSCapture, it works in draw. running windows on macbook.
Does anyone see what im doing wrong here? i'd really like to get it going using a .mov file (GSVideo) rather than the webcam (GSCapture). Thanks!!
import codeanticode.gsvideo.*;
import peasy.*;
//import processing.video.*;
int cellsize = 2; // Dimensions of each cell in the grid
int cols, rows; // Number of columns and rows in our system
//Movie mov;
//GSCapture mov; //unhide this to use the webcam and hide GSMovie below
GSMovie mov;
PeasyCam cam;
void setup() {
size(640, 480, P3D);
//mov = new Movie(this, "animation 1.mov");
mov = new GSMovie(this, "sponge animation.mov");
//mov = new GSCapture(this, width, height); // unhide this and below for webcam. hide above too
//mov.start();
cols = mov.width/cellsize; // Calculate # of columns
rows = mov.height/cellsize; // Calculate # of rows
cam = new PeasyCam(this,mov.width/2,mov.height/2,0,1000);
}
void movieEvent(GSMovie m) {
m.read();
m.loadPixels();
}
void draw() {
background(0);
// mov.read();
// mov.loadPixels();
// Begin loop for columns
for ( int i = 0; i < cols;i++) {
// Begin loop for rows
for ( int j = 0; j < rows;j++) {
int x = i*cellsize + cellsize/2; // x position
int y = j*cellsize + cellsize/2; // y position
int loc = x + y*mov.width; // Pixel array location
color c = mov.pixels[loc]; // Grab the color
// Calculate a z position as a function of mouseX and pixel brightness
float z = brightness((mov.pixels[loc]));
// Translate to the location, set fill and stroke, and draw the rect