We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello everyone!
I am absolutely new to processing and am attempting to use it for a school project.
I would like to control the for loop with input from a webcam instead of a mouse. (This code is ale's. http://www.openprocessing.org/sketch/42143):
PImage I;
int i,x,y,w=900,h=450;
void setup(){size(w,h);
I=loadImage("1.jpg");}
void draw()
{for(i=0;i++<w*h;)set((x=i%w)^mouseX,(y=i/w)^mouseY,I.get(x,y));}
I've looked into Golan Levin's frame differencing, flob blob tracking, and other methods of getting data out of captured video but I can't figure out how to use it in this instance. When running Levin's code without modification I get an error reading
"Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started"
and then the rendered window remains grey.
However I can run this sketch (http://www.openprocessing.org/sketch/58148) without a problem.
Thanks in advance for your help!
Answers
A simple approach would be to scan the webcam image looking for the brightest pixel, and then you replace mouseX and mouseY with the x and y of the brightest pixel. That means that you should use something bright to control the program, like a flash light or the screen of your cellphone.
This is not as fancy as blob tracking, but it can be done in a few lines of code, and painting with a flash light is also fun :)
You can also look for other properties, like the pixel with most red, or most blue, if you are wearing a glove with that color and everything else in the image does not have much of that color.
There's actually an example that does exactly what hamoid suggested in examples->libraries->video->capture->brightnesstracking