Mar 28 2009
Jmyron + controlP5 iteration #2
From the old version, the problem that was happening was that there setting all RGB values to one slider value would only detect black to white colors. I changed so that now the RGB channels can now be all set individually. It works a lot better as can be seen from the screenshot. The bright blue areas with the green outline are the blogs, I've set it to detect the red boxes in this screenshot.

And here's the code for it:
import JMyron.*; import controlP5.*; JMyron m; ControlP5 controlP5; int red_color = 0; int green_color = 0; int blue_color = 0; int sensitivity = 40; int min_size = 10; int max_size=10; String RGBValue = ""; int mouseX; int mouseY; void setup(){ int width = 720; int height = 576; size(width,height); m = new JMyron(); m.start(width,height); frameRate(30); println("Myron " + m.version()); noFill(); controlP5 = new ControlP5(this); controlP5.addSlider("R",0,255,0,10,10,10,50).setId(1); controlP5.addSlider("G",0,255,0,60,10,10,50).setId(2); controlP5.addSlider("B",0,255,0,100,10,10,50).setId(3); controlP5.addSlider("sensitivity",0,255,40,10,140,10,50).setId(4); controlP5.addSlider("min size",0,400,10,60,140,10,50).setId(5); controlP5.addSlider("max size",0,400,10,100,140,10,50).setId(6); } void draw(){ m.trackColor(red_color,green_color,blue_color,sensitivity); //m.minDensity(min_size); //m.maxDensity(max_size); float ir,ig,ib; m.update();//update the camera view int[] img = m.image(); //get the normal image of the camera //draw what the camera sees 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(); stroke(0,150,0); int[][][] list = m.globEdgePoints(30);//get the outlines for(int i=0;i <list.length;i++){ beginShape(); if(list[i]!=null){ for(int ii=0;ii<list[i].length;ii++){ vertex(list[i][ii][0],list[i][ii][1]); } } endShape(); } } void controlEvent(ControlEvent theEvent) { //if a control event is received from the P5 controller //println("got a control event from controller with id "+theEvent.controller().id()); //check from what controller it came //by looking for the ID element switch(theEvent.controller().id()) { //if the ID element is number 1 (the tracing color slider) case(1): red_color = (int)(theEvent.controller().value()); println("Red" + red_color); println("Green" + green_color); println("Blue" + blue_color); break; case(2): green_color = (int)(theEvent.controller().value()); break; case(3): blue_color = (int)(theEvent.controller().value()); break; case(4): sensitivity = (int)(theEvent.controller().value()); print("tracetolerance changed to " + sensitivity + "\n"); break; case(5): min_size = (int)(theEvent.controller().value()); break; case(6): max_size = (int)(theEvent.controller().value()); break; } } public void stop(){ m.stop();//stop the object super.stop(); }