| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,126 @@ | |||
| 1 | + /** | ||
| 2 | + * Spatiotemporal | ||
| 3 | + * by David Muth | ||
| 4 | + * | ||
| 5 | + * Records a number of video frames into memory, then plays back the video | ||
| 6 | + * buffer by turning the time axis into the x-axis and vice versa | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | + import processing.video.*; | ||
| 10 | + | ||
| 11 | + Capture video; | ||
| 12 | + int signal = 0; | ||
| 13 | + | ||
| 14 | + //the buffer for storing video frames | ||
| 15 | + ArrayList frames; | ||
| 16 | + | ||
| 17 | + //different program modes for recording and playback | ||
| 18 | + int mode = 0; | ||
| 19 | + int MODE_NEWBUFFER = 0; | ||
| 20 | + int MODE_RECORDING = 1; | ||
| 21 | + int MODE_PLAYBACK = 2; | ||
| 22 | + | ||
| 23 | + int currentX = 0; | ||
| 24 | + | ||
| 25 | + void setup() { | ||
| 26 | + size(640, 480); | ||
| 27 | + video = new Capture(this, width, height, 30); | ||
| 28 | + video.start(); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + void captureEvent(Capture c) { | ||
| 32 | + c.read(); | ||
| 33 | + | ||
| 34 | + //create a new buffer in case one is needed | ||
| 35 | + if (mode == MODE_NEWBUFFER) { | ||
| 36 | + frames = new ArrayList(); | ||
| 37 | + mode = MODE_RECORDING; | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + //record into the buffer until there are enough frames | ||
| 41 | + if (mode == MODE_RECORDING) { | ||
| 42 | + //copy the current video frame into an image, so it can be stored in the buffer | ||
| 43 | + PImage img = createImage(width, height, RGB); | ||
| 44 | + video.loadPixels(); | ||
| 45 | + arrayCopy(video.pixels, img.pixels); | ||
| 46 | + | ||
| 47 | + frames.add(img); | ||
| 48 | + | ||
| 49 | + //in case enough frames have been recorded, switch to playback mode | ||
| 50 | + if (frames.size() >= width) { | ||
| 51 | + mode = MODE_PLAYBACK; | ||
| 52 | + } | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + void draw() { | ||
| 57 | + loadPixels(); | ||
| 58 | + | ||
| 59 | + //code for the recording mode | ||
| 60 | + if (mode == MODE_RECORDING) { | ||
| 61 | + //set the image counter to 0 | ||
| 62 | + int currentImage = 0; | ||
| 63 | + | ||
| 64 | + //begin a loop for displaying pixel columns | ||
| 65 | + for (int x = 0; x < video.width; x++) { | ||
| 66 | + //go through the frame buffer and pick an image using the image counter | ||
| 67 | + if (currentImage < frames.size()) { | ||
| 68 | + PImage img = (PImage)frames.get(currentImage); | ||
| 69 | + | ||
| 70 | + //display a pixel column of the current image | ||
| 71 | + if (img != null) { | ||
| 72 | + img.loadPixels(); | ||
| 73 | + | ||
| 74 | + for (int y = 0; y < video.height; y++) { | ||
| 75 | + pixels[x + y * width] = img.pixels[x + y * video.width]; | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + //increase the image counter | ||
| 80 | + currentImage++; | ||
| 81 | + | ||
| 82 | + } | ||
| 83 | + else { | ||
| 84 | + break; | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + //code for displaying the spatiotemporal transformation | ||
| 90 | + if (mode == MODE_PLAYBACK) { | ||
| 91 | + | ||
| 92 | + //begin a loop for displaying pixel columns | ||
| 93 | + for (int x = 0; x < video.width; x++) { | ||
| 94 | + //get an image from the buffer using loopcounter x as the index | ||
| 95 | + PImage img = (PImage)frames.get(x); | ||
| 96 | + | ||
| 97 | + if (img != null) { | ||
| 98 | + img.loadPixels(); | ||
| 99 | + | ||
| 100 | + //pick the same column from each image for display, | ||
| 101 | + //then distribute the columns over the x-axis on the screen | ||
| 102 | + for(int y = 0; y < video.height; y++) { | ||
| 103 | + pixels[x + y * width] = img.pixels[currentX + y * video.width]; | ||
| 104 | + } | ||
| 105 | + } | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + //a different column shall be used next time draw() is being called | ||
| 109 | + currentX++; | ||
| 110 | + | ||
| 111 | + //if the end of the buffer is reached | ||
| 112 | + if(currentX >= video.width) { | ||
| 113 | + //create a new buffer when the next video frame arrives | ||
| 114 | + mode = MODE_NEWBUFFER; | ||
| 115 | + //reset the column counter | ||
| 116 | + currentX = 0; | ||
| 117 | + } | ||
| 118 | + } | ||
| 119 | + | ||
| 120 | + updatePixels(); | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + | ||
| 124 | + | ||
| 125 | + | ||
| 126 | + | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,79 @@ | |||
| 1 | + /** | ||
| 2 | + * Time Displacement | ||
| 3 | + * by David Muth | ||
| 4 | + * | ||
| 5 | + * Keeps a buffer of video frames in memory and displays pixel rows | ||
| 6 | + * taken from consecutive frames distributed over the y-axis | ||
| 7 | + */ | ||
| 8 | + | ||
| 9 | + import processing.video.*; | ||
| 10 | + | ||
| 11 | + Capture video; | ||
| 12 | + int signal = 0; | ||
| 13 | + | ||
| 14 | + //the buffer for storing video frames | ||
| 15 | + ArrayList frames = new ArrayList(); | ||
| 16 | + | ||
| 17 | + void setup() { | ||
| 18 | + size(640, 480); | ||
| 19 | + video = new Capture(this, width, height, 30); | ||
| 20 | + video.start(); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + void captureEvent(Capture camera) { | ||
| 24 | + camera.read(); | ||
| 25 | + | ||
| 26 | + //copy the current video frame into an image, so it can be stored in the buffer | ||
| 27 | + PImage img = createImage(width, height, RGB); | ||
| 28 | + video.loadPixels(); | ||
| 29 | + arrayCopy(video.pixels, img.pixels); | ||
| 30 | + | ||
| 31 | + frames.add(img); | ||
| 32 | + | ||
| 33 | + //once there are enough frames, remove the oldest one when adding a new one | ||
| 34 | + if(frames.size() > height/4) { | ||
| 35 | + frames.remove(0); | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + void draw() { | ||
| 40 | + //set the image counter to 0 | ||
| 41 | + int currentImage = 0; | ||
| 42 | + | ||
| 43 | + loadPixels(); | ||
| 44 | + | ||
| 45 | + //begin a loop for displaying pixel rows of 4 pixels height | ||
| 46 | + for(int y = 0; y < video.height; y+=4) { | ||
| 47 | + //go through the frame buffer and pick an image, starting with the oldest one | ||
| 48 | + if(currentImage < frames.size()) { | ||
| 49 | + PImage img = (PImage)frames.get(currentImage); | ||
| 50 | + | ||
| 51 | + if(img != null) { | ||
| 52 | + img.loadPixels(); | ||
| 53 | + | ||
| 54 | + //put 4 rows of pixels on the screen | ||
| 55 | + for(int x = 0; x < video.width; x++) { | ||
| 56 | + pixels[x + y * width] = img.pixels[x + y * video.width]; | ||
| 57 | + pixels[x + (y + 1) * width] = img.pixels[x + (y + 1) * video.width]; | ||
| 58 | + pixels[x + (y + 2) * width] = img.pixels[x + (y + 2) * video.width]; | ||
| 59 | + pixels[x + (y + 3) * width] = img.pixels[x + (y + 3) * video.width]; | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + //increase the image counter | ||
| 64 | + currentImage++; | ||
| 65 | + | ||
| 66 | + } else { | ||
| 67 | + break; | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + updatePixels(); | ||
| 72 | + | ||
| 73 | + //for recording an image sequence | ||
| 74 | + //saveFrame("frame-####.jpg"); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + | ||
| 78 | + | ||
| 79 | + | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments