-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrolFrame.pde
251 lines (215 loc) · 6.94 KB
/
controlFrame.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
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
class ControlFrame extends PApplet {
int w, h;
PApplet parent;
ControlP5 cp5;
int darkenCameraImage = 0;
public ControlFrame(PApplet _parent, int _w, int _h, String _name) {
super();
parent = _parent;
w=_w;
h=_h;
PApplet.runSketch(new String[]{this.getClass().getName()}, this);
}
public void settings() {
size(w, h);
}
public void setup() {
surface.setLocation(10, 10);
cp5 = new ControlP5(this);
cp5.addSlider("Brightness Threshold")
.plugTo(parent, "brightnessThreshold")
.setPosition(20, 45)
.setSize(250, 15)
.setRange(0, 50)
.setValue(80)
;
cp5.addSlider("Darken Camera Image")
.plugTo(this, "darkenCameraImage")
.setPosition(20, 65)
.setSize(250, 15)
.setRange(0, 100)
.setValue(0)
;
cp5.addSlider("Easing")
.plugTo(parent, "easeTraces")
.setPosition(20, 90)
.setSize(250, 30)
.setRange(0, 100)
.setValue(18)
;
cp5.addSlider("Thickness")
.plugTo(parent, "setEpaisseurBoitier")
.setPosition(20, 130)
.setSize(250, 30)
.setRange(0, 30)
.setValue(defaultEpaisseurThickness)
;
List l = Arrays.asList(modesAvailable);
/* add a ScrollableList, by default it behaves like a DropdownList */
cp5.addScrollableList("dropdown")
.setPosition(20, 180)
.setSize(200, 60)
.setBarHeight(20)
.setItemHeight(20)
.addItems(l)
.setType(ScrollableList.DROPDOWN) // currently supported DROPDOWN and LIST
;
if (allConnectedCameras.length > 0) {
List n = Arrays.asList(allConnectedCameras);
/* add a ScrollableList, by default it behaves like a DropdownList */
cp5.addScrollableList("allConnectedCameras")
.setPosition(20, 250)
.setSize(200, 170)
.setBarHeight(20)
.setItemHeight(20)
.addItems(n)
.setType(ScrollableList.DROPDOWN) // currently supported DROPDOWN and LIST
;
}
List m = Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ".", ",", "!", "?");
cp5.addScrollableList("selectionLettres")
.setPosition(width/2+10, 180)
.setSize(200, 130)
.setBarHeight(20)
.setItemHeight(20)
.addItems(m)
.setType(ScrollableList.DROPDOWN) // currently supported DROPDOWN and LIST
;
cp5.addToggle("Debug")
.plugTo(parent, "isDebug")
.setPosition(width - 80, 20)
.setSize(20, 20)
.setValue(false)
;
cp5.addButton("Start Over")
.plugTo(parent, "startOver")
.setPosition(20, 20)
.setSize(100, 20)
;
cp5.addButton("Export to SVG")
.plugTo(parent, "exportSVG")
.setPosition(width-120, height-40)
.setSize(100, 20)
;
background(0);
}
void draw() {
noStroke();
fill(21);
rect(0, 0, width, 450);
fill(41);
rect(0, 450 - 10, width, 20);
textAlign(CENTER, CENTER);
fill(255);
text("drawing letter " + setExportSuffix, width/2, 450);
if (currentMode == "camera") {
println("Got new camera frame");
fill(21);
rect(0, 450 + 10, width, height/2);
theBlobDetection.setThreshold(brightnessThreshold/100); // will detect bright areas whose luminosity > brightnessThreshold;
newFrame = false;
img.copy(cam, 0, 0, cam.width, cam.height, 0, 0, img.width, img.height);
fastblur(img, 2);
float darkenValue = darkenCameraImage/100.0f;
PImage flipped = createImage(img.width, img.height, RGB);//create a new image with the same dimensions
for (int i = 0; i < flipped.pixels.length; i++) { //loop through each pixel
int srcX = i % flipped.width; //calculate source(original) x position
int dstX = flipped.width-srcX-1; //calculate destination(flipped) x position = (maximum-x-1)
int y = i / flipped.width; //calculate y coordinate
color pixColor = lerpColor(img.pixels[i], color(0), darkenValue);
flipped.pixels[y*flipped.width+dstX] = pixColor;//write the destination(x flipped) pixel based on the current pixel
}
img = flipped;
theBlobDetection.computeBlobs(img.pixels);
PVector brightestBlobCenter = getBrightestBlobCenter();
if (brightestBlobCenter.mag() > 0) {
println("Found a bright point at x=" + pointToTrace.x + " y=" + pointToTrace.y);
} else {
println("No lights detected");
}
pointToTrace = brightestBlobCenter.copy();
pushMatrix();
translate(30, 450 + 30);
image(img, 0, 0);
drawBlobsAndEdges(true, true);
popMatrix();
}
}
void dropdown(int n) {
/* request the selected item based on index n */
currentMode = cp5.get(ScrollableList.class, "dropdown").getItem(n).get("name").toString();
}
void selectionLettres(int n) {
println("select Letter");
setExportSuffix = cp5.get(ScrollableList.class, "selectionLettres").getItem(n).get("name").toString();
}
void allConnectedCameras(int n) {
cam.stop();
println("Switch to feed : " + allConnectedCameras[n]);
cam = null;
cam = new Capture(parent, allConnectedCameras[n]);
cam.start();
}
void drawBlobsAndEdges(boolean drawBlobs, boolean drawEdges) {
noFill();
Blob b;
EdgeVertex eA, eB;
for (int n=0; n<theBlobDetection.getBlobNb(); n++)
{
b=theBlobDetection.getBlob(n);
if (b!=null)
{
// Edges
if (drawEdges)
{
strokeWeight(3);
stroke(0, 255, 0);
for (int m=0; m<b.getEdgeNb(); m++)
{
eA = b.getEdgeVertexA(m);
eB = b.getEdgeVertexB(m);
if (eA !=null && eB !=null)
line(
eA.x*img.width, eA.y*img.height,
eB.x*img.width, eB.y*img.height
);
}
}
// Blobs
if (drawBlobs)
{
strokeWeight(1);
stroke(255, 0, 0);
rect(
b.xMin*img.width, b.yMin*img.height,
b.w*img.width, b.h*img.height
);
}
}
}
}
void keyReleased() {
// dodoc box, blue arrow left
if (key == 'w') {
// reduce stroke weight
setEpaisseurBoitier = setEpaisseurBoitier <= 0 ? 0 : (setEpaisseurBoitier - 2);
// dodoc box, blue arrow right
} else if (key == 's') {
setEpaisseurBoitier = setEpaisseurBoitier >= 20 ? 20 : (setEpaisseurBoitier + 2);
// dodoc box, green button
} else if (key == 'a') {
recordSVG = true;
} else if (key == '1') {
setExportSuffix = 'w' + "";
} else if (key == '2') {
setExportSuffix = 'a' + "";
} else if (key == '3') {
setExportSuffix = 's' + "";
} else if (key==' ') {
startOver();
} else {
setExportSuffix = key + "";
}
println("setEpaisseurBoitier ? " + setEpaisseurBoitier);
}
}