what works for CAPTURE wont work for MOVIE!! Why?
in
Programming Questions
•
2 years ago
Hi i was trying to achieve a 3d pixel effect from a video modifying a script i made for a capture...
But for the video I keep on getting an "ArrayIndexOutOfBoundsException: 4810" error !!!
Where am I wrong ?
This is the code working with a CAPTURE
Could someone help me please...
Thank you all !
But for the video I keep on getting an "ArrayIndexOutOfBoundsException: 4810" error !!!
Where am I wrong ?
This is the code working with a CAPTURE
- import processing.video.*;
Capture video;
int cellsize = 20;
int cols, rows;
void setup() {
size(640,480,P3D);
video = new Capture(this,width,height,30); // Load the video
cols = width/cellsize; // Calculate # of columns
rows = height/cellsize; // Calculate # of rows
}
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++ ) {
int x = i*cellsize + cellsize/2; // x position
int y = j*cellsize + cellsize/2; // y position
int loc = x + y*width; // Pixel array location
color c = video.pixels[loc]; // Grab the color
// Calculate a z position as a function of pixel brightness
float z = -(800/(float)width) * brightness(video.pixels[loc])- 100.0;
// Translate to the location, set fill and stroke, and draw the rect
pushMatrix();
rotateY(0.5);
translate(x,y,z);
fill(c);
noStroke();
rectMode(CENTER);
rect(0,0,cellsize,cellsize);
popMatrix();
}
}
}
- import processing.video.*;
Movie video;
int cellsize = 20; // Dimensions of each cell in the grid
int cols, rows; // Number of columns and rows in our system
void setup() {
size(480,480,P3D);
video = new Movie(this,"filmato.mov"); // Load the image
//video = new Capture(this,width,height,30);
video.loop();
cols = width/cellsize; // Calculate # of columns
rows = height/cellsize; // Calculate # of rows
try {
quicktime.QTSession.open();
} catch (quicktime.QTException qte) {
qte.printStackTrace();
}
}
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++ ) {
int x = i*cellsize + cellsize/2; // x position
int y = j*cellsize + cellsize/2; // y position
int loc = x + y*width; // Pixel array location
color c = video.pixels[loc]; // Grab the color
// Calculate a z position as a function of pixel brightness
float z = -(500/(float)width) * brightness(video.pixels[loc])- 100.0;
// Translate to the location, set fill and stroke, and draw the rect
pushMatrix();
//
rotateY(0.5);
translate(x,y,z);
// fill(c);
noStroke();
rectMode(CENTER);
rect(0,0,cellsize,cellsize);
popMatrix();
}
}
}
Could someone help me please...
Thank you all !
1