|
@@ -0,0 +1,163 @@
|
|
1
|
+//Video2Minitel
|
|
2
|
+//by Renaud, Fabrice & Phil
|
|
3
|
+//Inspired from Video2ledwallHarpSerial V1.0 by Fabrice Fourc
|
|
4
|
+// http://www.tetalab.org
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+import processing.video.*;
|
|
8
|
+import processing.net.*;
|
|
9
|
+int plage=44;//256;
|
|
10
|
+int MINITEL_CHAR_WIDTH = 40;//*2;
|
|
11
|
+int MINITEL_CHAR_HEIGHT = 24;//*4;
|
|
12
|
+ // en fait ce n'est pas vraiment un pixel par pixel char...
|
|
13
|
+int PIXEL_CHAR_WIDTH = 2;
|
|
14
|
+int PIXEL_CHAR_HEIGHT = 3;
|
|
15
|
+
|
|
16
|
+// Size of each cell in the grid, ratio of window size to video size
|
|
17
|
+int videoScale = 10;
|
|
18
|
+int videoScalex = 8;
|
|
19
|
+int videoScaley = 6;
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+// Number of columns and rows in our system
|
|
24
|
+int cols, rows;
|
|
25
|
+// Variable to hold onto Capture object
|
|
26
|
+public int s = 50;
|
|
27
|
+import processing.serial.*;
|
|
28
|
+
|
|
29
|
+// The serial port:
|
|
30
|
+Serial myPort;
|
|
31
|
+
|
|
32
|
+//luminosite globale de la colone pour le son
|
|
33
|
+int colValue;
|
|
34
|
+String ledCol;
|
|
35
|
+String ledWallMsg;
|
|
36
|
+
|
|
37
|
+//Client myClient;
|
|
38
|
+Capture video;
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+void setup()
|
|
44
|
+{
|
|
45
|
+ size(MINITEL_CHAR_WIDTH*PIXEL_CHAR_WIDTH*videoScalex,MINITEL_CHAR_HEIGHT*PIXEL_CHAR_HEIGHT*videoScaley);
|
|
46
|
+ frameRate(25);
|
|
47
|
+
|
|
48
|
+ // List all the available serial ports:
|
|
49
|
+ println(Serial.list());
|
|
50
|
+
|
|
51
|
+ // I know that the first port in the serial list on my mac
|
|
52
|
+ // is always my Keyspan adaptor, so I open Serial.list()[0].
|
|
53
|
+ // Open whatever port is the one you're using.
|
|
54
|
+ myPort = new Serial(this, Serial.list()[1], 1200);
|
|
55
|
+
|
|
56
|
+ //myClient = new Client(this, "127.0.0.1", 5204);
|
|
57
|
+ // Initialize columns and rows
|
|
58
|
+ cols = width/videoScalex;
|
|
59
|
+ rows = height/videoScaley;
|
|
60
|
+ video = new Capture(this,cols,rows,30);
|
|
61
|
+}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+//----------------------------------------------------------
|
|
65
|
+
|
|
66
|
+void displayPixelChar2(int x, int y)
|
|
67
|
+{
|
|
68
|
+ x= x *2;
|
|
69
|
+ y = y * 3;
|
|
70
|
+ byte carac=0; // caractère pixel
|
|
71
|
+ carac+=(Math.pow(2,0))*getG2(x+0,y+0);
|
|
72
|
+ carac+=(Math.pow(2,1))*getG2(x+1,y+0);
|
|
73
|
+ carac+=(Math.pow(2,2))*getG2(x+0,y+1);
|
|
74
|
+ carac+=(Math.pow(2,3))*getG2(x+1,y+1);
|
|
75
|
+ carac+=(Math.pow(2,4))*getG2(x+0,y+2);
|
|
76
|
+ carac+=(Math.pow(2,5))*1;
|
|
77
|
+ carac+=(Math.pow(2,6))*getG2(x+1,y+2);
|
|
78
|
+ myPort.write(carac);
|
|
79
|
+ println("carac= "+carac);
|
|
80
|
+}
|
|
81
|
+
|
|
82
|
+int getG2(int x,int y)
|
|
83
|
+{
|
|
84
|
+ println("x + y*video.width" + (x + y*video.width));
|
|
85
|
+ color c = video.pixels[x + y*video.width];
|
|
86
|
+ int value = (int)brightness(c); // get the brightness
|
|
87
|
+ if (value<s)
|
|
88
|
+ {
|
|
89
|
+ return(0);
|
|
90
|
+ }
|
|
91
|
+ else
|
|
92
|
+ {
|
|
93
|
+ return(1);
|
|
94
|
+ }
|
|
95
|
+}
|
|
96
|
+
|
|
97
|
+void draw() {
|
|
98
|
+ // Read image from the camera
|
|
99
|
+ noStroke();
|
|
100
|
+
|
|
101
|
+ if (video.available())
|
|
102
|
+ {
|
|
103
|
+ video.read();
|
|
104
|
+ }
|
|
105
|
+ video.loadPixels();
|
|
106
|
+
|
|
107
|
+ if(!mousePressed) //si je ne clique pas, j'affiche le preview
|
|
108
|
+ {
|
|
109
|
+ image(video,0,0);
|
|
110
|
+ // Begin loop for columns
|
|
111
|
+ for (int i = 0; i < cols; i++)
|
|
112
|
+ {
|
|
113
|
+ // Begin loop for rows
|
|
114
|
+ for (int j = 0; j < rows; j++)
|
|
115
|
+ {
|
|
116
|
+ // Where are we, pixel-wise?
|
|
117
|
+ int x = i*videoScalex;
|
|
118
|
+ int y = j*videoScaley;
|
|
119
|
+ // Looking up the appropriate color in the pixel array
|
|
120
|
+ color c = video.pixels[i + j*video.width];
|
|
121
|
+ int value = (int)brightness(c); // get the brightness
|
|
122
|
+ if (value<s)
|
|
123
|
+ {
|
|
124
|
+ fill(0);
|
|
125
|
+ }
|
|
126
|
+ else
|
|
127
|
+ {
|
|
128
|
+ fill(255);
|
|
129
|
+ }
|
|
130
|
+ rect(x,y,videoScalex,videoScaley);
|
|
131
|
+ }
|
|
132
|
+ ledWallMsg += ledCol;
|
|
133
|
+ }
|
|
134
|
+ }
|
|
135
|
+ else //si je clique sur l'image j'envoi sur le port serie
|
|
136
|
+ {
|
|
137
|
+ myPort.write(12);
|
|
138
|
+ myPort.write(14);
|
|
139
|
+ for (int y=0;y<MINITEL_CHAR_HEIGHT;y++)
|
|
140
|
+ {
|
|
141
|
+ for (int x=0;x<MINITEL_CHAR_WIDTH;x++)
|
|
142
|
+ {
|
|
143
|
+ displayPixelChar2(x,y);
|
|
144
|
+ println("x= "+x+"y= "+y);
|
|
145
|
+ }
|
|
146
|
+ }
|
|
147
|
+ }
|
|
148
|
+}
|
|
149
|
+
|
|
150
|
+void keyPressed() //reglage du seuil (a-, z+)
|
|
151
|
+{
|
|
152
|
+ if( key == 'a')
|
|
153
|
+ {
|
|
154
|
+ s = s - 1;
|
|
155
|
+ println("s " + s);
|
|
156
|
+ }
|
|
157
|
+ if ( key == 'z')
|
|
158
|
+ {
|
|
159
|
+ s = s + 1;
|
|
160
|
+ println("s " + s);
|
|
161
|
+ }
|
|
162
|
+}
|
|
163
|
+
|