Hi I'm trying to track my mouse with a web cam onto the screen so that the movement becomes a line. At the moment it takes the average movement and draws up a line, but there is also a lot of squares drawn out that I would like to get rid of. Pleaaaaaaase help me?
Best,
Jenny
This is how it looks at the moment:
The code I'm using is:
/*
the green oval is an averaged position of all the detected dark movement in the camera's view.
physical setup:
- make sure there is a strong value contrast between your hand and a white background.
- set all camera settings to "manual" for the most stable results.
last tested to work in Processing 0090
JTNIMOY
*/
import JMyron.*;
JMyron m;//a camera object
//variables to maintain the floating green circle
float objx = 160;
float objy = 120;
float objdestx = 160;
float objdesty = 120;
float[] xHist;
float[] yHist;
int xHistIndex = 0;
int yHistIndex = 0;
void setup(){
size(1440,900);
xHist = new float[1000]; // hur manga frames man kan lagra
yHist = new float[1000];
m = new JMyron();//make a new instance of the object
m.start(width,height);//start a capture at 320x240
m.trackColor(255,255,255,256*3-100);//track white
m.update();
m.adaptivity(10);
m.adapt();// immediately take a snapshot of the background for differencing
println("Myron " + m.version());
rectMode(CENTER);
noStroke();
}
void draw(){
m.update();//update the camera view
drawCamera();
int[][] centers = m.globCenters();//get the center points
//draw all the dots while calculating the average.
float avX=0;
float avY=0;
for(int i=0;i<centers.length;i++){
fill(80);
rect(centers[i][0],centers[i][1],5,5);
avX += centers[i][0];
avY += centers[i][1];
}
if(centers.length-1>0){
avX/=centers.length-1;
avY/=centers.length-1;
}
//draw the average of all the points in red.
fill(255,0,0);
// rect(avX,avY,5,5);
//update the location of the thing on the screen.
if(!(avX==0&&avY==0)&¢ers.length>0){
objdestx = avX;
objdesty = avY;
}
objx += (objdestx-objx)/5.0f;
objy += (objdesty-objy)/5.0f;
fill(30,100,0);
ellipseMode(CENTER);
xHist[xHistIndex++] = objx;
yHist[yHistIndex++] = objy;
for(int i=1; i<xHistIndex; i++) {
//ellipse(xHist[i],yHist[i],10,10);// hur tjockt streck (tva sista vardena)
stroke(255,0,0);
line(xHist[i-1],yHist[i-1],xHist[i],yHist[i]);
}
}
void drawCamera(){
// int[] img = m.differenceImage(); //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();
}
void mousePressed(){
m.settings();//click the window to get the settings
}
public void stop(){
m.stop();//stop the object
super.stop();
}