the fuzz

import processing.video.*;
Capture video;

// keep track of the previous frame of video
PImage prevFrame;

// threshold to qualify a pixel as being different
int threshold = 30;

void setup()
{
  size(640, 480);
  video = new Capture(this, 640, 480); 
  video.start(); 
  noStroke();

  // create a previous frame PImage
  prevFrame = new PImage(640, 480);
}

void draw()
{

  if (video.available())
  {
    // take the current frame of video and copy it into our previous frame of video
    video.loadPixels();
    prevFrame.loadPixels();
    arrayCopy(video.pixels, prevFrame.pixels);
    prevFrame.updatePixels();

    // now read a new frame of video
    video.read();
  }

  // display the current frame of the video on the stage
  image(video, 0, 0);

  // load the pixels on the stage 
  loadPixels();

  int woot = 0;

  // now we can figure out which pixels are different between the previous frame and our current frame
  video.loadPixels();
  prevFrame.loadPixels();
  for (int x = 0; x < video.width; x++)
  {
    for (int y = 0; y < video.height; y++)
    {
      // determine our location
      int location = x + y*video.width;

      // compare the pixels
      float curRed   = red(video.pixels[location]);
      float curGreen = green(video.pixels[location]);
      float curBlue  = blue(video.pixels[location]);
      float prevRed   = red(prevFrame.pixels[location]);
      float prevGreen = green(prevFrame.pixels[location]);
      float prevBlue  = blue(prevFrame.pixels[location]);
      float difference = dist(curRed, curGreen, curBlue, prevRed, prevGreen, prevBlue);
      if (difference > threshold)
      {
       //give color so we can see movement 
        pixels[location] = color(163, 255, 240);
        woot++;
      }
    }
  }

  // update the pixels on the screen
  updatePixels();

  //border

  //left
  fill(163, 255, 240);
  rect(0, 0, 20, 480);

  //right
  fill(163, 255, 240);
  rect(620, 0, 20, 480);

  //bottom
  fill(163, 255, 240);
  rect(0, 460, 640, 20);

  //top
  fill(163, 255, 240);
  rect(0, 0, 640, 20);
}

I made a simple motion detector making images out of previous frames. The change in RGB color is detected and then given a color to emphasize the change.

 

Video

Leave a Reply