We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi guys;
I'm pretty new to Processing, so these problems are probably really easily fixed, but hey-oh.
I'd really appreciate any insight you can offer!
I'm getting the error ArrayIndexOutOfBoundsException:0 when I try to run this code:
import processing.video.*;
Capture cam;
PImage frame;
PImage destination;
void setup() {
String[] cameras = Capture.list();
if (cameras.length == 0) {
println("There are no cameras available for capture.");
exit();
} else {
println("Available cameras:");
for (int x=0;x<cameras.length;x++) {
println(cameras[x]);
}
cam = new Capture(this, cameras[0]);
cam.start();
}
size(360,240);
frame = createImage(cam.width,cam.height,RGB);
destination = createImage(cam.width,cam.height,RGB);
println("setup");
}
void draw() {
if (cam.available() == true) {
cam.read();
println("cam read");
}
cam.loadPixels();
frame.loadPixels();
for(int x=0;x<cam.width;x++) {
for (int y=0;y<cam.height;y++) {
int loc = x+y*cam.width;
frame.pixels[loc] = cam.pixels[loc];
}
}
println("pixels copied");
int threshold = 127;
for(int x=0;x<cam.width;x++) {
for (int y=0;y<cam.height;y++) {
int loc = x+y*cam.width;
if (brightness(frame.pixels[loc]) <= threshold) {
destination.pixels[loc] = color(0);
} else {
destination.pixels[loc] = color(255);
}
}
}
destination.updatePixels();
image(destination,0,0);
println("printed");
}
Thanks in advance!
P.S. The code isn't displaying correctly in my browser, if it happens for anyone else I apologise! EDIT: it's working now, thanks to GoToLoop.
Answers
http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text
Aha, thank you!
Seems like somehow cam.pixels[] was mysteriously a 0-length array at times. :-/
Rather than trying to find out why, I've just picked a working Capture example I've already got here.
Then thrown in the pixels[] & brightness() stuff back in order to have a similar sketch to yours.
Oh, wonderful! Thank you very much :-) Thoroughly appreciated!
Glad you've liked it! >:D<
BtW, here's v2.3 which I believe it's got a better performance than v2.2!
This time it uses a separate thread("") just for the RGBtoBW() conversion: :ar!
Oh, wow, thank you! I'll now set about running this and trying to figure out what on earth it all does... Thank you!
Some references for it: :D
try
-> https://processing.org/reference/try.htmlcatch ()
-> https://processing.org/reference/catch.htmlsynchronized
-> http://docs.oracle.com/javase/tutorial/essential/concurrency/locksync.htmlOh my goodness, thank you! I really don't know what to say, I wasn't expecting this much information :-)