GMU:Eval(nature)/Andre Faupel: Difference between revisions

From Medien Wiki
No edit summary
No edit summary
Line 1: Line 1:
==Pixel Motion Detection -- File Input ==


<pre style="font=2">
import processing.video.*;
Movie cam;
PImage save, out;


//// threshold for fine-tuning and artefacts
[http://www.uni-weimar.de/medien/wiki/images/Drops_evalnature_color_trails.zip sketch for visual juicing]
float thresh = 2;


void setup() {
[[File:Af_drops_simple_trails.png|720px|thumb|left|trails]]
 
[[File:Af_drops_color_corr.png|560px|thumb|left|color correction]]
 
  ///change to your footage path
  cam = new Movie(this, "E:/vids/MVI_5018.MOV");
 
 
  cam.loop();
  cam.jump(random(cam.duration()));
  cam.volume(0);
 
 
  // set windows size to match footage resolution
  size(cam.width, cam.height);
 
 
  ///setup previous frame and output-image
  save = createImage(cam.width, cam.height, RGB);
  out = createImage(cam.width, cam.height, RGB);
}
 
void draw() {
 
  loadPixels();
  motiondetect();
 
  out.updatePixels();
  image(out, 0, 0, width, height);
}
 
 
void motiondetect() {
 
  cam.loadPixels();
  save.loadPixels();
 
 
  ///scann through input pixels
  for (int x = 0; x < cam.width; x ++ ) {
    for (int y = 0; y < cam.height; y ++ ) {
      int loc = y*cam.width+x;   
      color c = cam.pixels[loc];     
      color c_l = save.pixels[loc];
 
      ///get colors of each pxl
      float r = red(c);
      float g = green(c);
      float b = blue(c);
      ///get colors of each pxl -> prev frame
      float r_l = red(c_l);
      float g_l = green(c_l);
      float b_l = blue(c_l);
 
      ///compare
      float dif = dist(r, g, b, r_l, g_l, b_l);
 
      ///exchange pxls to make change visible
      if (dif>thresh) {
        out.pixels[loc] = color (abs(r-r_l), abs(g-g_l), abs(b-b_l));
      } else {
        out.pixels[loc] = color (0);
      }
    }
  }
}
 
 
void movieEvent(Movie m) {
 
  ///get cam image and copy as previous frame
  if (m.available()) {
    save = m.get();
    save.updatePixels();
    m.read();
  }
}
 
 
 
 
 
</pre>

Revision as of 17:13, 4 May 2015


sketch for visual juicing

trails
color correction