-
Notifications
You must be signed in to change notification settings - Fork 0
/
FrameDifferencing.pde
81 lines (65 loc) · 2.71 KB
/
FrameDifferencing.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// filter 4
// treba mu sto godina da se pokrene, popravit
/**
* Frame Differencing
* by Golan Levin.
*
* Quantify the amount of movement in the video frame using frame-differencing.
*/
//int numPixels;
//int[] previousFrame;
////Capture video;
//void f_frameDifferencing_setup() {
// //size(640, 480);
// // This the default video input, see the GettingStartedCapture
// // example if it creates an error
// cam = new Capture(this, width, height);
// // Start capturing the images from the camera
// cam.start();
// numPixels = width * height;
// // Create an array to store the previously captured frame
// previousFrame = new int[numPixels];
// loadPixels();
// ime_filtera = "Frame Differencing";
//}
//void f_frameDifferencing_draw() {
// if (cam.available()) {
// // When using video to manipulate the screen, use video.available() and
// // video.read() inside the draw() method so that it's safe to draw to the screen
// //video.read(); // Read the new frame from the camera
// cam.loadPixels(); // Make its pixels[] array available
// int movementSum = 0; // Amount of movement in the frame
// for (int i = 0; i < numPixels; i++) { // For each pixel in the video frame...
// //INDEKS ISKACE
// color currColor = cam.pixels[i];
// color prevColor = previousFrame[i];
// // Extract the red, green, and blue components from current pixel
// int currR = (currColor >> 16) & 0xFF; // Like red(), but faster
// int currG = (currColor >> 8) & 0xFF;
// int currB = currColor & 0xFF;
// // Extract red, green, and blue components from previous pixel
// int prevR = (prevColor >> 16) & 0xFF;
// int prevG = (prevColor >> 8) & 0xFF;
// int prevB = prevColor & 0xFF;
// // Compute the difference of the red, green, and blue values
// int diffR = abs(currR - prevR);
// int diffG = abs(currG - prevG);
// int diffB = abs(currB - prevB);
// // Add these differences to the running tally
// movementSum += diffR + diffG + diffB;
// // Render the difference image to the screen
// pixels[i] = color(diffR, diffG, diffB);
// // The following line is much faster, but more confusing to read
// //pixels[i] = 0xff000000 | (diffR << 16) | (diffG << 8) | diffB;
// // Save the current color into the 'previous' buffer
// previousFrame[i] = currColor;
// }
// // To prevent flicker from frames that are all black (no movement),
// // only update the screen if the image has changed.
// if (movementSum > 0) {
// updatePixels();
// //image(cam, 0, 0, WindowWidth, WindowHeight);
// //println(movementSum); // Print the total amount of movement to the console
// }
// }
//}