Advertisement
xeromino

balou

Mar 5th, 2016
227
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import gab.opencv.*;
  2.  
  3. OpenCV opencv;
  4. String dir = "jungle", delay = "0.1";
  5. int num = 24, counter;
  6. PImage  before, after, grayDiff;
  7. PImage[] pics = new PImage[num];
  8. PImage[] grayDiffs = new PImage[num-1];
  9.  
  10. void settings() {
  11.   before = loadImage(dir+"/frame_0_delay-" + delay + "s.gif");
  12.   int w = before.width;
  13.   size(w, before.height);
  14. }
  15.  
  16. void setup() {
  17.   background(0);
  18.   frameRate(10);
  19.   //load original images in array
  20.   for (int i=0; i<num; i++) {
  21.     pics[i] = loadImage(dir+"/frame_" + i + "_delay-" + delay + "s.gif");
  22.   }
  23.   // create grayDiffs from those images
  24.   for (int i=0; i<grayDiffs.length; i++) {
  25.     doStuff(i);
  26.   }
  27. }
  28.  
  29. void doStuff(int i) {
  30.   if (i<num-1) {
  31.     before = pics[i];
  32.     after = pics[i+1];  
  33.     opencv = new OpenCV(this, before);    
  34.     opencv.diff(after);
  35.     grayDiff = opencv.getSnapshot();
  36.     grayDiffs[i] = grayDiff;
  37.   }
  38. }
  39.  
  40. void draw() {
  41.   tint(255,150);
  42.   image(grayDiffs[frameCount%grayDiffs.length],0,0);
  43.   if (frameCount<num) saveFrame("image-###.gif");
  44. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement