-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHackNights_05FrameDifferencing.pde
More file actions
64 lines (50 loc) · 1.4 KB
/
HackNights_05FrameDifferencing.pde
File metadata and controls
64 lines (50 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import processing.video.*;
// this is the number of pixels that have to change between consecutive frames.
int MOVEMENT_THRESHOLD = 20000;
int numPixels;
boolean debug = false;
int flashValue = 0;
Capture video;
PImage frameDiff, previousFrame;
void setup() {
size(640, 480);
frameRate(30);
video = new Capture(this, width, height);
video.start();
frameDiff = createImage(width, height, ARGB);
previousFrame = createImage(width, height, ARGB);
numPixels = video.width * video.height;
}
void draw() {
if (video.available()) {
video.read();
video.loadPixels();
frameDiff.loadPixels();
previousFrame.loadPixels();
int movementSum = 0;
for (int i = 0; i < numPixels; i++) {
int frameDiffB = abs((video.pixels[i]&0xFF) - (previousFrame.pixels[i]&0xFF));
movementSum += (frameDiffB>64)?frameDiffB:0;
frameDiff.pixels[i] = color(frameDiffB);
previousFrame.pixels[i] = video.pixels[i];
}
previousFrame.updatePixels();
frameDiff.updatePixels();
// FLASH
flashValue = max(0, flashValue-12);
if (movementSum > MOVEMENT_THRESHOLD && flashValue==0) {
flashValue = 255;
println("FLASH");
}
// draw stuff
background(0);
image(debug?frameDiff:video, 0, 0);
fill(flashValue, flashValue);
rect(0, 0, width, height);
}
}
void keyPressed() {
if (key == ' ' || key == 'd' || key == 'D') {
debug = !debug;
}
}