We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Tracking, squares flying around (Read 1280 times)
Tracking, squares flying around
Oct 18th, 2007, 6:59pm
 
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)&&centers.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();
}


Re: Tracking, squares flying around
Reply #1 - Oct 19th, 2007, 10:21am
 
Unsure of how JMyron tracks objects, but could the blocks be small objects that it has found because of noise in the image etc ?
Re: Tracking, squares flying around
Reply #2 - Oct 20th, 2007, 12:49am
 
jenny,

looking at the code... the squares are the points of which your "mouse" movement is averaged of. They are drawn in the first for-loop of your draw method. And because you're not clearing the background each frame, they add up.
http://processing.org/reference/background_.html
Page Index Toggle Pages: 1