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.
IndexDiscussionGeneral Discussion,  Status › Help for interactive installation
Page Index Toggle Pages: 1
Help for interactive installation (Read 1255 times)
Help for interactive installation
Feb 12th, 2007, 2:07pm
 
Hello all,

I want to use processing and arduino to make an installation move in the same direction as the viewer that will walk in front of it. I am trying to use videotracking with a camrecorder or a web camera, to track the position of the viewer and send the information to arduino, in order to make the installation move in the correct direction. Here is the code that I am working on, but for some reason beyond my knowledge, it is not working:

import processing.video.*;

// Variable for capture device
Capture video;
color trackColor;


void setup()
{
 size(200, 200);
 frameRate(30);
 colorMode(RGB,255,255,255,100);
 // Using the default capture device
 video = new Capture(this, 200, 200, 12);
 trackColor = color(0); // Start off tracking for white
 noFill();
 smooth();
 strokeWeight(4.0);
 stroke(0);
}

void captureEvent(Capture camera)
{
 camera.read();
}

void draw()
{

 loadPixels();
 
 // Draw the video image on the background
 image(video,0,0);
 // Local variables to track the color
 float closestDiff = 100.0f;
 int newx = 0;
 int oldx = 0;
 int oldupdatex = 0;
 int closestX = 0;
 int closestY = 0;
 int updatex = 0;
 int[] Xs = new int[2];
Xs[0] = 0;
Xs[1] = 0;

int[] upXs = new int[2];
upXs[0] = 0;
upXs[1] = 0;

int count = 0;

 // Begin loop to walk through every pixel
 for ( int x = 0; x < video.width; x++) {
  // for ( int y = 0; y < video.height; y++) {
   //  int loc = x + y*video.width;
     int loc = x + (video.width * 100);
     // What is current color
     color currentColor = video.pixels[loc];
     float r1 = red(currentColor); float g1 = green(currentColor); float b1 = blue(currentColor);
     float r2 = red(trackColor);   float g2 = green(trackColor);   float b2 = blue(trackColor);
   
     // Using euclidean distance to compare colors
     float d = dist(r1,g1,b1,r2,g2,b2);
     // If current color is more similar to tracked color than
     // closest color, save current location and current difference
     if (d < closestDiff) {
   //  println (Xs[0] + "               " + Xs[1]);
   // if (x > 0){
       
    // println (Xs[0] + "              " + Xs[1]);
 
      closestDiff = d;
       closestX = x;
       Xs[0] = Xs[1];
      Xs[1] = x;
  //  }
   // else {Xs[0] = 999;
  //  Xs[1] = 0;
  //   }

 

   
   }
 
//  }
if (Xs[0] == 0) {
 
 updatex = Xs[1];

// upXs[1] = updatex;
 if (updatex > 0) {
  // upXs[0] = upXs[1];
 oldx = newx;
 newx = updatex;
   //upXs[1] = updatex;
   // println(upXs[0] + "            " + upXs[1]);
 // println (oldx +"            " + newx);
  println (oldx);
 }
}



 }


 // Draw a circle at the tracked pixel
 ellipse(Xs[1],100,16,16);
 ellipse(Xs[0], 50, 16, 16);


}

void mousePressed() {
 // Save color where the mouse is clicked in trackColor variable
 int loc = mouseX + mouseY*video.width;
 trackColor = video.pixels[loc];
 
}


Can anybody help me to uderstand why it is not working, please?

P.S. Please note that I am a novice in processing, therefore it could be something very easy that I just can't see.

Thanks again

Re: Help for interactive installation
Reply #1 - Apr 12th, 2007, 3:19am
 
I have not pored throught your code. However, I would recommend checking out "Physical Computing" by Tom Igoe and Dan O'Sullivan. They give several implementations of color tracking, including one using Processing, which seems to be where you're stuck at the moment. Additionally, it will give you a good foundation for solving any kind of physical computing problem. Also, I think this post might belong on either the Programs or Electronics board.
Page Index Toggle Pages: 1