Thanks for your feedback philho and Kevin, I really appreciate it.
Kevin, yes you are right. I didn't look hard enough and I was trying to over-complicate things.Your solution is very simple and elegant and I'm sure it should work great if I can get my code to function properly. I think my code is just organized badly but I can't figure out why it won't run.
Here it is:
- /*
- 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.*;
- Robot KeyBot; //Robot class for keypress
- JMyron m;//a camera object
- void setup(){
- size(320,240);
- m = new JMyron();//make a new instance of the object
- m.start(width,height);//start a capture at 320x240
- m.findGlobs(1);
- m.trackColor(0,0,0,200);//R, G, B, and range of similarity
- m.minDensity(1000); //minimum pixels in the glob required to result in a box
- println("Myron " + m.version());
- noFill();
- nBlobs = 0;
-
-
-
- try
- {
- KeyBot = new Robot();
- }
- catch (AWTException e)
- {
- println("Robot class not supported");
- exit();
- }
-
- }
- void draw(){
- m.update();//update the camera view
- drawCamera();//draw the camera to the screen
-
- int[][] b = m.globBoxes();//get list of bounding boxes
-
- //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] );
- }
-
- countTheBlobs();
-
- 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 countTheBlobs() {
- int blobcount = b.length; //Number of blobs onscreen
- if (blobcount < 3){ //constrain values from 2 to 6
- blobcount = 2;
- }
- if (blobcount > 5){
- blobcount = 6;
- }
-
- if (blobcount != nBlob) { //compares initial value to earlier value
- keyPressAction(); // if false, causes keypress
- nBlobs = blobcount; // refreshes current value
- }
- void mousePressed(){
- m.settings();//click the window to get the settings
- }
- public void stop(){
- m.stop();//stop the object
- super.stop();
- }
- void keyPressAction() {
- if (blobcount == 2) {
- KeyBot.keyPress(74);//press J key
- KeyBot.keyRelease(74);
- KeyBot.keyPress(74);//press J key
- KeyBot.keyRelease(74);
- }
- if (blobcount == 3) {
- KeyBot.keyPress(75);//press K key
- KeyBot.keyRelease(75);
- KeyBot.keyPress(75);//press K key
- KeyBot.keyRelease(75);
- }
- if (blobcount == 4) {
- KeyBot.keyPress(76);//press L key
- KeyBot.keyRelease(76);
- KeyBot.keyPress(76);//press L key
- KeyBot.keyRelease(76);
- }
- if (blobcount == 5) {
- KeyBot.keyPress(78);//press N key
- KeyBot.keyRelease(78);
- KeyBot.keyPress(78);//press N key
- KeyBot.keyRelease(78);
- }
- if (blobcount == 6) {
- KeyBot.keyPress(77);//press M key
- KeyBot.keyRelease(77);
- KeyBot.keyPress(77);//press M key
- KeyBot.keyRelease(77);
- }
I'm getting an unexpected token error (void) on the draw camera. The basic blob detection was working fine before and runs well for me. Sorry for my ignorance. I'm stuck right now. If anyone can see a problem or give me some organizational tips for my code I would be a happy camper.
Thanks again for all the help!