|
|
(5 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
| | =Sound and Video Processing = |
|
| |
|
| == Image Sortin == | | == Video Processing == |
| | === Video Delay === |
|
| |
|
| === Pixel Sorting === | | <source lang="java"> |
|
| |
|
| <source lang="java">
| | import processing.video.*; |
| PImage img;
| | |
| int id = 1; | | Capture camera; |
| int sortMode = 1;
| | int maxFrames; |
| | int d = 4; |
| | boolean recording = false; |
|
| |
|
| void setup() {
| | ArrayList frames = new ArrayList(); |
| size(600, 400);
| |
| reset();
| |
| }
| |
|
| |
|
| void reset() {
| |
| img = loadImage("winterpark.jpg");
| |
| }
| |
|
| |
|
| void draw() { | | void setup() { |
|
| |
| // load em
| |
| img.loadPixels();
| |
|
| |
| color[] pxls = img.pixels;
| |
| | | |
| switch(sortMode) { | | size(640, 480); |
| case 1:
| |
| sortLeft(pxls);
| |
| break;
| |
| case 2:
| |
| sortDown(pxls);
| |
| break;
| |
| case 3:
| |
| sortUp(pxls);
| |
| break;
| |
| }
| |
| | | |
| | maxFrames = width / d; |
| | | |
| // update em | | // init camera |
| img.updatePixels(); | | camera = new Capture(this, width, height); |
| | | |
| // show em | | camera.start(); // wichtig! |
| image(img, 0, 0);
| |
| | | |
| | // add first image |
| | PImage img = createImage(width, height, RGB); |
| | frames.add(img); |
|
| |
|
| } | | } |
|
| |
|
|
| |
|
| void sortLeft(color[] pxls) { | | void draw() { |
| | | |
| // do something with the pixels (remix them) | | int n = frames.size(); |
| for(int y = 0; y < height; y++) { | | |
| | // 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); |
| | | |
| for(int x = 0; x < width-1 ; x++) {
| |
|
| |
| // get indices for left and right pixel
| |
| int left = y * img.width + x;
| |
| int right = y * img.width + (x+1);
| |
|
| |
| // bubble sort step ( exchange pixels according to saturation ... )
| |
| int posx = mouseX - width / 2;
| |
|
| |
| if(green(pxls[right]) - green(pxls[left]) < posx) {
| |
| // exchange color values of those pixels
| |
| color tmp= pxls[right];
| |
| pxls[right] = pxls[left];
| |
| pxls[left] = tmp;
| |
| }
| |
| }
| |
| } | | } |
| | | |
| }
| | if(recording) { |
| | | |
| void sortDown(color[] pxls) {
| | saveFrame("frame-####.png"); |
| | |
| // do something with the pixels (remix them)
| |
| for(int x = 0; x < width; x++) {
| |
| | | |
| for(int y = height - 2; y > 0 ; y--) { | | // recording feedback |
| | stroke(255, 0, 0); |
| | noFill(); |
| | strokeWeight(5); |
| | rect(0, 0, width, height); |
|
| |
|
| // get indices for left and right pixel
| |
| int top = y * img.width + x;
| |
| int bottom = (y+1) * img.width + x;
| |
|
| |
| // bubble sort step ( exchange pixels according to saturation ... )
| |
| int posx = mouseX - width / 2;
| |
|
| |
| if(green(pxls[top]) - green(pxls[bottom]) < posx) {
| |
| // exchange color values of those pixels
| |
| color tmp= pxls[top];
| |
| pxls[top] = pxls[bottom];
| |
| pxls[bottom] = tmp;
| |
| }
| |
| }
| |
| } | | } |
| | |
| } | | } |
|
| |
|
| | void keyPressed() { |
| | recording = !recording; |
| | } |
|
| |
|
| void sortUp(color[] pxls) { | | void captureEvent(Capture camera) { |
| | | |
| // do something with the pixels (remix them) | | camera.read(); // wichtig! |
| for(int x = 0; x < width; x++) { | | PImage img = camera.get(); |
|
| | |
| for(int y = 0; y < height -1 ; y++) {
| | frames.add(img); |
| | | |
| // get indices for left and right pixel
| | if( frames.size() > maxFrames) { |
| int top = y * img.width + x;
| | frames.remove(0); |
| int bottom = (y+1) * img.width + x;
| | } |
|
| |
| // bubble sort step ( exchange pixels according to saturation ... )
| |
| int posx = mouseX - width / 2;
| |
|
| |
| if(green(pxls[top]) - green(pxls[bottom]) < posx) {
| |
| // exchange color values of those pixels
| |
| color tmp= pxls[top];
| |
| pxls[top] = pxls[bottom];
| |
| pxls[bottom] = tmp;
| |
| }
| |
| }
| |
| } | |
| | | |
| }
| |
|
| |
| void keyPressed() {
| |
| switch(key) {
| |
| case ' ':
| |
| reset();
| |
| break;
| |
| case 's':
| |
| save("sorted-" + id +".jpg");
| |
| id++;
| |
| break;
| |
| case '1':
| |
| sortMode = 1;
| |
| break;
| |
| case '2':
| |
| sortMode = 2;
| |
| break;
| |
| case '3':
| |
| sortMode = 3;
| |
| break;
| |
| }
| |
| } | | } |
| </source> | | </source> |