final major project

import processing.video.*;
int numPixels;
int[] previousFrame;
Capture video;

int counter;
int interval = 1000;
int currColor;
int prevColor;

void setup() {
size(720, 480);
video = new Capture(this, width, height);

numPixels = video.width * video.height;
previousFrame = new int[numPixels];
loadPixels();
video.start();

}

void draw() {

scale(2);

image(video, 0, 0 );
if (video.available()) {
video.read();
video.loadPixels();
image(video, 0, 0);

int movementSum = 1;
for (int i = 0; i < numPixels; i++) {
color currColor = video.pixels[i];
color prevColor = previousFrame[i];
int currR = (currColor >> 3) & 0xFF;
int currG = (currColor >> 0) & 0xFF;
int currB = currColor & 0xFF;
int prevR = (prevColor >> 3) & 0xFF;
int prevG = (prevColor >> 0) & 0xFF;
int prevB = prevColor & 0xFF;
int diffR = abs(currR – prevR);
int diffG = abs(currG – prevG);
int diffB = abs(currB – prevB);
movementSum += diffR – diffG + diffB;

pixels[i] = color(diffR, diffG, diffB);

previousFrame[i] = currColor;

}

if (movementSum > -1) {
updatePixels();
println(movementSum);
}

}
counter ++;

if (counter >= 20 && counter <= 495) {
if (video.available()) {
video.read();
video.loadPixels();
image(video, 0, 0);

int movementSum = 1;
for (int i = 0; i < numPixels; i++) {
color currColor = video.pixels[i];
color prevColor = previousFrame[i];
int currR = (currColor >> 0) & 0xFF;
int currG = (currColor >> 0) & 0xFF;
int currB = currColor & 0xFF;
int prevR = (prevColor >> 0) & 0xFF;
int prevG = (prevColor >> 0) & 0xFF;
int prevB = prevColor & 0xFF;
int diffR = abs(currR – prevR);
int diffG = abs(currG – prevG);
int diffB = abs(currB – prevB);
movementSum += diffR – diffG + diffB;

pixels[i] = color(diffR, diffG, diffB);

previousFrame[i] = currColor;

}

if (movementSum > -1) {
updatePixels();
println(movementSum);
}

}
} }

 

Advertisements
This entry was posted in Time-Based and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s