-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA_02_Read_Images_05B.pde
278 lines (223 loc) · 7.53 KB
/
A_02_Read_Images_05B.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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
import processing.opengl.*;
import processing.video.*;
//----GLOBAL VARIABLES----
String path; // this will hold the file path of the sketch
//MovieMaker MainMovie; // this will record the main screen
int ImageCount = 0; // used for calling the image files
int Factor = 4;
int ColorScale = 70000;
int PixelCount = 0;
int W =320; // screen resolution
int H = 240;
int MainMovieTimer = 0; // used to trigger saving the main movie
int MainMovieCounter = 0;
int ImageSaveCount = 0;
PImage img;
char ActiveKey = 'R';
char ActiveKey2 = 'S';
int s= second();
//----MULTI THREAD----
Thread t1, t2;
//----MULTI THREAD----
//----CAMERA VARIABLES----
int CamSaveCount = 0;
SaveImg cam;
//----CAMERA VARIABLES----
//----DISPLAY VARIABLES----
Display_Cam display;
int cx = W ;
int cy = (H / 2) * 7;
int cz = 100;
int tx = W;
int ty = H / 2;
int tz = 90;
//----DISPLAY VARIABLES----
//----GLOBAL VARIABLES----
//-------------------------------------------------------------------------------
void setup() {
path = sketchPath(""); // this is the folder directory of the sketch
//println ("Sketch path: " + path);
CreateFolders(path + "Pixel_Images");
CreateFolders(path + "Cam_Images");
//CreateFolders(path + "Movie");
//img = loadImage("C:\\Users\\Crashnorun\\Documents\\Image Sketch\\Image_03\\_01_Save_Images_01\\Cam_Images\\Img_" + ImageCount + ".jpg"); // Get the image from the camera
img = loadImage("Cam_Images\\Img_" + ImageCount + ".jpg"); //load the first image
//size(img.width*2, img.height*2, P3D);
size(640, 480, P3D);
frameRate(15);
background(0);
//MainMovie = new MovieMaker(this, width, height, "Movie\\Main_" + MainMovieCounter + ".mov"); // record the main screen
directionalLight(255, 255, 255, 1, 1, -1); //rgb values andx,y,z coord //<>//
ambientLight(255, 255, 255); //ambient light
display = new Display_Cam(cx, cy, cz, tx, ty, tz, 0.0, 1.0, 0.0); // Create a display camera
cam = new SaveImg(this, W, H, path);
//t1 = new Thread(cam);
//t1.start();
cam.run(CamSaveCount);
//cam.SaveImages(CamSaveCount);
CamSaveCount ++;
//cam.SaveImages(CamSaveCount);
cam.run(CamSaveCount);
CamSaveCount ++;
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
void draw() {
background(0); //<>//
camera(display.CX, display.CY, display.CZ, display.TX, display.TY, display.TZ, display.UpX, display.UpY, display.UpZ); // Use the display properties to set the camera
img = loadImage("Cam_Images\\Img_" + ImageCount + ".jpg");
//----SAVE IMAGES FROM CAMERA----
cam.run(CamSaveCount);
if (CamSaveCount >=100) {
CamSaveCount = 0;
} else {
CamSaveCount ++;
}
//----SAVE IMAGES FROM CAMERA----
if (key == '0') { // Number 2 button shows the image
image(img, 0, 0);
display.CX = img.width / 2;
display.CY = img.height / 2;
display.CZ = img.height;
display.TX = img.width / 2;
display.TY = img.height / 2;
display.TZ = 0;
} else {
img.loadPixels();
PixelCount = 0;
for (int i = 0; i < img.height; i += Factor) {
for (int j = 0; j < img.width; j += Factor) {
println("Pixel Count = " + PixelCount + " X= " + i + " Y= " + j);
color c = color(red(img.pixels[PixelCount]), green(img.pixels[PixelCount]), blue(img.pixels[PixelCount]));
stroke(c);
fill(c);
pushMatrix();
translate(j*2, i*2, abs(c / ColorScale));
rect(0, 0, Factor*2, Factor*2);
popMatrix();
PixelCount+=Factor;
} // close J loop
PixelCount = i * img.width ;
if (i ==4) {
//System.exit(0);
}
} // close I loop
} // close keyprssed conditional statement
if (ImageCount >=100) {
ImageCount = 0;
} else {
ImageCount++;
}
//----SAVE IMAGES----
if (second() % 2 == 0) {
PImage img2 = createImage(width, height, RGB);
//img2 = display.Image(width, height);
img2.loadPixels();
//println(img2.pixels[0]);
save("Pixel_Images\\Image_" + ImageSaveCount + ".png");
//img2.save("Pixel_Images\\Image_" + ImageSaveCount + ".png");
if (ImageSaveCount >=100) {
ImageSaveCount = 0;
} else {
ImageSaveCount++;
}
}
//----SAVE IMAGES----
System.gc();
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
// Create the appropiate file paths
private void CreateFolders(String FilePath) {
File folder = new File(FilePath);
if (!folder.exists()) { //check if file path exists
println("creating directory: " + FilePath);
folder.mkdir(); //make the file path
} else {
println("Path: '" + FilePath + "' already exists");
}
}
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
// When the space bar is pressed the main movie saves and exits processing
void keyPressed() {
int temp;
switch (key) {
case ' ':
exit(); // Quit running the sketch once the file is written
break;
case '+': // Zoom in
temp = display.CY;
display.CY = temp - 10;
temp = display.TY;
display.TY = temp - 10;
//println(display.CY);
break;
case '-': // Zoom out
temp = display.CY;
display.CY = temp + 10;
temp = display.TY;
display.TY = temp + 10;
//println(display.CY);
break;
case '1': // Reset camera to original position
display.CX = cx;
display.CY = cy;
display.CZ = cz;
display.TX = tx;
display.TY = ty;
display.TZ = tz;
break;
case '3': // Show original image
image(img, 0, 0);
break;
case '4': // Alternate view
display.CZ = 1000;
break;
case '5': // Alternate view
display.CZ = 100;
display.CY = 750;
break;
case '*': // this chanes the color height;
temp = ColorScale;
ColorScale = temp - 1000;
break;
case '/':
temp = ColorScale;
ColorScale = temp + 1000;
break;
case '2': // Reset color scale
ColorScale = 70000;
break;
default:
switch (keyCode) {
case UP: // Move Camera Up
temp = display.CZ;
display.CZ = temp + 10;
//println(display.CZ);
break;
case DOWN: // Move Camera Down
temp = display.CZ;
display.CZ = temp - 10;
//println(display.CZ);
break;
case LEFT: // Move Camera Left
temp = display.CX;
display.CX = temp - 10;
temp = display.TX;
display.TX = temp - 10;
//println(display.CX);
break;
case RIGHT: // Move Camera Right
temp = display.CX;
display.CX = temp + 10;
temp = display.TX;
display.TX = temp + 10;
//println(display.CX);
break;
}
break;
}
//println("key: " + key);
}
//-------------------------------------------------------------------------------