I'm using Processing 090 and JMyron 0023, and have modified the example "Myron_BoundingBoxes" to try and track 3 colors: red, orange and yellow-green. The problem I'm getting seems to be occuring when trying to find globs for seperate colors and reading their center points from arrays. My intention is to draw a seperate rectangle for each of the 3 colors, however this code draws all 3 rectangles for each color. When I comment out the last two rectangles, it draws the first rectangle (green rect, meant to be drawn only for a red glob) for all the colors. Any ideas? I'm still learning, so I'm guessing this is a programming error on my part.
Code:
/*
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_r;//Red LED camera object
JMyron m_y;//YelloGreen LED camera object
JMyron m_o;//Orange LED camera object
void setup(){
size(320,240);
m_r = new JMyron();//make a new instance of the object
m_y = new JMyron();//make a new instance of the object
m_o = new JMyron();//make a new instance of the object
m_r.start(width,height);//start a capture at 320x240
m_r.trackColor(255,0,0,200);//R, G, B, and range of similarity
m_r.minDensity(100); //minimum pixels in the glob required to result in a box
m_y.trackColor(100,255,0,200);//R, G, B, and range of similarity
m_y.minDensity(100); //minimum pixels in the glob required to result in a box
m_o.trackColor(200,100,0,200);//R, G, B, and range of similarity
m_o.minDensity(100); //minimum pixels in the glob required to result in a box
println("Myron " + m_r.version());
noFill();
}
void draw(){
m_r.update();//update the camera view
m_y.update();//update the camera view
m_o.update();//update the camera view
drawCamera();//draw the camera to the screen
//background(50);
int[][] b_r = m_r.globBoxes();//get the center points
int[][] b_y = m_y.globBoxes();//get the center points
int[][] b_o = m_o.globBoxes();//get the center points
//draw the boxes
stroke(0,255,0); //draw a green rect for the red glob (offset so it doesn't draw on top of other rectangles)
for(int i=0;i<b_r.length;i++){
rect( (b_r[i][0])-10 , (b_r[i][1])+10 , (b_r[i][2])-10 , (b_r[i][3])+10 );
}
stroke(255,0,0); //draw a red rect for the yellow-green glob (offset so it doesn't draw on top of other rectangles)
for(int i=0;i<b_y.length;i++){
rect( (b_y[i][0])-5 , (b_y[i][1])+5 , (b_y[i][2])-5 , (b_y[i][3])+5 );
}
stroke(0,0,255); //draw a blue rect for the orange glob
for(int i=0;i<b_o.length;i++){
rect( b_o[i][0] , b_o[i][1] , b_o[i][2] , b_o[i][3] );
}
}
void drawCamera(){
int[] img = m_r.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_r.settings();//click the window to get the settings
}
public void stop(){
m_r.stop();//stop the object
m_y.stop();//stop the object
m_o.stop();//stop the object
super.stop();
}