I have the same problem. Now I use the library JMyron and try to combine the brightness tracking function with using webcam as mouse function. It works well when it has only one brightest glob in the screen. However, if there are multi brightest globs, the camera just get to confuse. I guess "boolean[]" would control each mouse's availability, and give true/fales value to each new mouse...
I have no idea now
this is my code and if any one can continue it...:
import JMyron.*;
JMyron m;
int maxMice = 5;
// flags that control each mouse's availability
boolean[] isFree = new boolean[maxMice];
float objx = 320;
float objy = 240;
float objdestx = 320;
float objdesty = 240;
void setup(){
size(320,240);
m = new JMyron();//make a new instance of the object
m.start(width,height);//start a capture
m.trackColor(255,255,255,2);//R, G, B, and range of similarity
m.minDensity(100); //minimum pixels in the glob required to result in a box
println("Myron " + m.version());
noFill();
}
void draw(){
m.update();//update the camera view
//background(255);
drawCamera();//draw the camera to the screen
int[][] b = m.globBoxes();//get the center points
float avX=0;
float avY=0;
//draw the boxes
stroke(255,0,0);
for(int i=0;i<b.length;i++){
rect( b[i][0] , b[i][1] , b[i][2] , b[i][3] );
avX += b[i][0];
avY += b[i][1];
}
if(b.length-1>0){
avX/=b.length-1;
avY/=b.length-1;
}
//mouse follow
if(!(avX==0&&avY==0)&&b.length>0){
objdestx = avX;
objdesty = avY;
}
objx += (objdestx-objx)/10.0f;
objy += (objdesty-objy)/10.0f;
noFill();
ellipse(objx,objy,30,30);
}
void drawCamera(){
int[] img = m.image(); //get the normal image of the camera
loadPixels();
for(int i=0;i<width*height;i++){ //loop through all the pixels
pixels[i] = img[i]; //draw each pixel to the screen
}
updatePixels();
}
public void stop(){
m.stop();//stop the object
super.stop();
}