-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexampleMotionTrack.html
227 lines (168 loc) · 7.36 KB
/
exampleMotionTrack.html
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Motion Track Kepler movementDash</title>
<link rel="icon" href="/img/processing-1.ico" type="image/x-icon" />
<link rel="shortcut icon" href="/img/processing-1.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Keywords" content="Processing, Processing, Interactive Media, Electronic Arts, Programming, Java, Ben Fry, Casey Reas" />
<script src="http://www.processing.org/javascript/MM_functions.js" type="text/javascript"></script>
<script src="http://www.processing.org/javascript/processing.js" type="text/javascript"></script>
<script src="http://www.processing.org/javascript/jquery-1.2.6.min.js" type="text/javascript"></script>
<script src="http://www.processing.org/javascript/slideshow.js" type="text/javascript"></script>
<link href="../../css/style.css" rel="stylesheet" type="text/css" />
</head>
<body id="Basics" onload="" >
<div class="example">
<script type="application/processing">
// Tracks the brightest pixel in a live video signal
Capture video;
void setup(){
size(720, 480); // Change size to 320 x 240 if too slow at 640 x 480
video = new Capture(this, width, height, 30);
noStroke();
smooth();
}
ArrayList<String> queue = new ArrayList();
String[] direction = {"UL", "UR", "DL", "DR"};
String directionFound;
ArrayList<Integer[]> demarcation1 = new ArrayList();
ArrayList<Integer[]> demarcation2 = new ArrayList();
int prev_brightestX = 0; // prev X-coordinate of the brightest video pixel
int prev_brightestY = 0; // prev Y-coordinate of the brightest video pixel
String movement = ""; //DL= 1, DR= 1, UL= 0, UR= 0 possible values
String continuingDirection = "UR"; //Set early- requires 10 frames to clear
int diffDirUL = 0; int diffDirUR = 0; int diffDirDL = 0; int diffDirDR = 0;
Boolean compareDemarcations = false;
Boolean span1 = true;
Boolean start = true;
Boolean ret = false;
String currDir;
int qCount = 0;
int count = 0;
void draw() {
if (video.available()) {
video.read();
image(video, 0, 0, width, height); // Draw the webcam video onto the screen
if (count%30 == 0){
//println(" " );
//println(" ============================================== " );
}
//print(count);
count += 1;
int brightestX = 0; // X-coordinate of the brightest video pixel
int brightestY = 0; // Y-coordinate of the brightest video pixel
float brightestValue = 0; // Brightness of the brightest video pixel
// Search for the brightest pixel: For each row of pixels in the video image
//and for each pixel in the yth row, compute each pixel's index in the video
video.loadPixels();
int index = 0;
for (int y = 0; y < video.height; y++) {
for (int x = 0; x < video.width; x++) {
// Get the color stored in the pixel
int pixelValue = video.pixels[index];
// Determine the brightness of the pixel
float pixelBrightness = brightness(pixelValue);
// If that value is brighter than any previous, then store the
// brightness of that pixel, as well as its (x,y) location
if (pixelBrightness > brightestValue){
brightestValue = pixelBrightness;
brightestY = y;
brightestX = x;
}
index++;
}
}
// Draw a large, yellow circle at the brightest pixel
fill(255, 204, 0, 128); ellipse(brightestX, brightestY, 50, 50);
//print("[" + brightestX); print(", " + brightestY + "]; ");
//print("BP@: " + brightestX); print(" " + brightestY); //println(" ");
Integer[] coords = {brightestX, brightestY};
if (span1){
if (ret == true){
////println("DEMARCATION #1 " + demarcation1);
////println("DEMARCATION #2 " + demarcation2);
}
demarcation1.add(coords);
}else{
demarcation2.add(coords);
ret = true;
}
// Determine the direction of the flashlight movement
if (prev_brightestX - brightestX > 0){
if (prev_brightestY - brightestY > 0){
movement = "DL";
queue.add(movement);
println(" " +movement);
////println("PREV X "+ (prev_brightestX - brightestX) + " & PREV Y " + (prev_brightestY - brightestY) +" " + movement);
}else{
movement= "UL";
queue.add(movement);
println(" " +movement);
////println("PREV X "+ (prev_brightestX - brightestX) + " & PREV Y " + (prev_brightestY - brightestY) +" " + movement);
}
} else{
if (prev_brightestY - brightestY > 0){
movement = "DR";
queue.add(movement);
println(" " +movement);
////println("PREV X "+ (prev_brightestX - brightestX) + " & PREV Y " + (prev_brightestY - brightestY) +" " + movement);
}else{
movement = "UR";
queue.add(movement);
////println("PREV X "+ (prev_brightestX - brightestX) + " & PREV Y " + (prev_brightestY - brightestY) +" " + movement);
println(" " +movement);
}
}
prev_brightestX = brightestX; prev_brightestY = brightestY;
if (queue.size() == 5){
int ul_count = 0; int ur_count = 0;
int dr_count = 0; int dl_count = 0;
for (int dir= 0; dir< 5; dir++){
if (queue.get(dir) == "UL"){
ul_count += 1;
}
if (queue.get(dir) == "UR"){
ur_count += 1;
}
if (queue.get(dir) == "DL"){
dl_count += 1;
}
if (queue.get(dir) == "DR"){
dr_count += 1;
}
}
queue = new ArrayList(); //RESET
int[] countList = {ul_count, ur_count, dl_count, dr_count}; //PARAMETER|| FOR SOME Reason this is all really UR heavy try this
int maxCount = max(countList);
for (int i=0; i<4; i++){
if (countList[i] == maxCount){
String directionFound = direction[i];
//print( "----------- AVERAGE " + directionFound);
}
}
if (directionFound != continuingDirection){
if (directionFound == "UL"){
diffDirUL += 1;
}else if (directionFound == "UR"){
diffDirUR += 1;
}else if (directionFound == "DL"){
diffDirDL += 1;
}else if (directionFound == "DR"){
diffDirDR += 1;
}
int[] diffDirMsr = {diffDirUL, diffDirUR, diffDirDL, diffDirDR};
if (max(diffDirMsr) == 2){
//This might need to be modified so that, instead of waiting for 5
diffDirUL = 0; diffDirUR = 0; diffDirDL = 0; diffDirDR = 0;
span1 = !span1;
continuingDirection = directionFound;
}
}
}
}
}
</script>
</div>
</body>
</html>