-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunction.pde
46 lines (40 loc) · 1.25 KB
/
function.pde
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
// motion compare current and previous frame to get b/w image
PImage motion = createImage(wwidth, hheight, RGB);
int motionThreshold = 33;
PImage motion() {
video.loadPixels();
prev.loadPixels();
motion.loadPixels();
//loadPixels();
// Begin loop to walk through every pixel
// Begin loop to walk through every pixel
for (int x = 0; x < video.width; x++ ) {
for (int y = 0; y < video.height; y++ ) {
int loc = x + y * video.width;
// What is current color
color currentColor = video.pixels[loc];
float r1 = red(currentColor);
float g1 = green(currentColor);
float b1 = blue(currentColor);
color prevColor = prev.pixels[loc];
float r2 = red(prevColor);
float g2 = green(prevColor);
float b2 = blue(prevColor);
float d = distSq(r1, g1, b1, r2, g2, b2);
if (d > motionThreshold * motionThreshold) {
//stroke(255);
//strokeWeight(1);
//point(x, y);
motion.pixels[loc] = color(255);
} else {
motion.pixels[loc] = color(0);
}
}
}
motion.updatePixels();
return motion;
}
float distSq(float x1, float y1, float z1, float x2, float y2, float z2) {
float d = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) +(z2-z1)*(z2-z1);
return d;
}