(complex sorting example) |
No edit summary |
||
(5 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
=Sound and Video Processing = | |||
== | == Video Processing == | ||
=== Video Delay === | |||
= | <source lang="java"> | ||
import processing.video.*; | |||
int | Capture camera; | ||
int maxFrames; | |||
int d = 4; | |||
boolean recording = false; | |||
ArrayList frames = new ArrayList(); | |||
void | void setup() { | ||
size(640, 480); | |||
maxFrames = width / d; | |||
// | // init camera | ||
camera = new Capture(this, width, height); | |||
camera.start(); // wichtig! | |||
// add first image | |||
PImage img = createImage(width, height, RGB); | |||
frames.add(img); | |||
} | } | ||
void | void draw() { | ||
// | int n = frames.size(); | ||
for(int | |||
// iterate over vertical strips | |||
for(int i = 0; i < n; i++) { | |||
// get snip from the frame | |||
PImage img = (PImage) frames.get(i); | |||
// x coordinate for the left side of the current strip | |||
int x1 = int(map(i, 0, n-1, 0, width/2 - 100)); | |||
int y1 = int(map(i, 0, n-1, 0, height/2 - 100)); | |||
int x2 = width - x1; | |||
int y2 = height - y1; | |||
int w = x2 - y1; | |||
int h = y2 - y1; | |||
PImage snip = img.get(x1, y1, w, h); | |||
// show strip on screen | |||
//tint(255, 50); | |||
image(snip, x1, y1); | |||
} | } | ||
if(recording) { | |||
saveFrame("frame-####.png"); | |||
// recording feedback | |||
stroke(255, 0, 0); | |||
noFill(); | |||
strokeWeight(5); | |||
rect(0, 0, width, height); | |||
} | } | ||
} | } | ||
void keyPressed() { | |||
recording = !recording; | |||
} | |||
void | void captureEvent(Capture camera) { | ||
camera.read(); // wichtig! | |||
PImage img = camera.get(); | |||
frames.add(img); | |||
if( frames.size() > maxFrames) { | |||
frames.remove(0); | |||
} | |||
} | |||
} | } | ||
</source> | </source> |
Latest revision as of 12:44, 21 January 2016
Sound and Video Processing
Video Processing
Video Delay
import processing.video.*;
Capture camera;
int maxFrames;
int d = 4;
boolean recording = false;
ArrayList frames = new ArrayList();
void setup() {
size(640, 480);
maxFrames = width / d;
// init camera
camera = new Capture(this, width, height);
camera.start(); // wichtig!
// add first image
PImage img = createImage(width, height, RGB);
frames.add(img);
}
void draw() {
int n = frames.size();
// iterate over vertical strips
for(int i = 0; i < n; i++) {
// get snip from the frame
PImage img = (PImage) frames.get(i);
// x coordinate for the left side of the current strip
int x1 = int(map(i, 0, n-1, 0, width/2 - 100));
int y1 = int(map(i, 0, n-1, 0, height/2 - 100));
int x2 = width - x1;
int y2 = height - y1;
int w = x2 - y1;
int h = y2 - y1;
PImage snip = img.get(x1, y1, w, h);
// show strip on screen
//tint(255, 50);
image(snip, x1, y1);
}
if(recording) {
saveFrame("frame-####.png");
// recording feedback
stroke(255, 0, 0);
noFill();
strokeWeight(5);
rect(0, 0, width, height);
}
}
void keyPressed() {
recording = !recording;
}
void captureEvent(Capture camera) {
camera.read(); // wichtig!
PImage img = camera.get();
frames.add(img);
if( frames.size() > maxFrames) {
frames.remove(0);
}
}