/**
* Time Displacement
* by David Muth
*
* Keeps a buffer of video frames in memory and displays pixel rows
* taken from consecutive frames distributed over the y-axis
*/
import processing.video.*;
Capture video;
int signal = 0;
//the buffer for storing video frames
ArrayList frames = new ArrayList();
void setup() {
size(640, 480);
// This the default video input, see the GettingStartedCapture
// example if it creates an error
video = new Capture(this, width, height);
// Start capturing the images from the camera
video.start();
}
void captureEvent(Capture camera) {
camera.read();
// Copy the current video frame into an image, so it can be stored in the buffer
PImage img = createImage(width, height, RGB);
video.loadPixels();
arrayCopy(video.pixels, img.pixels);
frames.add(img);
// Once there are enough frames, remove the oldest one when adding a new one
if (frames.size() > height/4) {
frames.remove(0);
}
}
void draw() {
// Set the image counter to 0
int currentImage = 0;
loadPixels();
// Begin a loop for displaying pixel rows of 4 pixels height
for (int y = 0; y < video.height; y+=4) {
// Go through the frame buffer and pick an image, starting with the oldest one
if (currentImage < frames.size()) {
PImage img = (PImage)frames.get(currentImage);
if (img != null) {
img.loadPixels();
// Put 4 rows of pixels on the screen
for (int x = 0; x < video.width; x++) {
pixels[x + y * width] = img.pixels[x + y * video.width];
pixels[x + (y + 1) * width] = img.pixels[x + (y + 1) * video.width];
pixels[x + (y + 2) * width] = img.pixels[x + (y + 2) * video.width];
pixels[x + (y + 3) * width] = img.pixels[x + (y + 3) * video.width];
}
}
// Increase the image counter
currentImage++;
} else {
break;
}
}
updatePixels();
// For recording an image sequence
if (key == 's') {saveFrame("/output/seq-####.tif");}
//saveFrame("frame-####.jpg");
SoundCipher sc = new SoundCipher(this);
PImage img = loadImage("111.jpg");
int s=img.width*img.height;
size(img.width, img.height);
image(img, 0, 0);
img.loadPixels();
float[][] pixelss = new float[4][s];
//
float SumRed=0;
float SumGreen=0;
float SumBlue=0;
int ij=1;
for (int i = 0; i < img.width; i++) {
for (int j = 0; j < img.height; j++) {
SumRed=SumRed+red(get (i,j));
SumGreen=SumGreen+green(get (i,j));
SumBlue=SumBlue+blue(get (i,j));
ij++;
// print(red(get (i,j))+" = ");
}
}
//print(SumRed);
print("red - "+SumRed/s+"; green - "+SumGreen/s+"; blue - "+SumBlue/s);
fill(SumRed/s,SumGreen/s,SumBlue/s);
noStroke();
background(255);
rect(int(img.width/4),int(img.height/4) , int(img.width/2),int(img.height/2));