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
Playing two JMyron instants. (Read 334 times)
Playing two JMyron instants.
Nov 2nd, 2008, 12:33am
 
Alright so I'm trying to track two colours at once, now I've experiemented and I really can't get it to work, if I try to make two complete camera layered it just has a fatal error, if I just try and make another tracking colour it just ignores one of the track colours.

/*
bounding boxes is a simple object tracking example.
point the camera at some big bright objects and the boxes will follow.

last tested to work in Processing 0090

JTNIMOY

*/


import JMyron.*;

JMyron m;//a camera object
JMyron n;

void setup(){
 size(800,600);
 m = new JMyron();//make a new instance of the object
 n = new JMyron();
 m.start(width,height);//start a capture at 320x240
 n.start(width,height);
 m.trackColor(4,24,159,30);//R, G, B, and range of similarity
 n.trackColor(7,70,72,30);
 m.minDensity(100);
 n.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
 drawCamera();//draw the camera to the screen
 drawCamera2();//draw the camera to the screen
 int[][] b = m.globBoxes();//get the center points
 int[][] c = n.globBoxes();
 println("C: " + c.length);
 println("B: " + b.length);  



 //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] );
 }

 fill(0,255,0);
 for(int i=0;i<c.length;i++){
   rect( c[i][0] , c[i][1] , c[i][2] , c[i][3] );
 }
}

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();

}

void drawCamera2(){
 int[] img = n.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();

}


void mousePressed(){
 m.settings();//click the window to get the settings
}

public void stop(){
 m.stop();//stop the object
 super.stop();
}



Any idea of how to track two colours?
I need both to be track by different code because I'm then going to take the length of the center points, average them, and have a single point which is in the middle of all of it.
Page Index Toggle Pages: 1