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
Jmyron Glob Detection and Timed Event (Read 438 times)
Jmyron Glob Detection and Timed Event
Dec 1st, 2009, 4:30pm
 
My question comes in 2 parts but first I will describe my sketch's purpose.

The goal of this sketch is that while capture device is running (Im using JMyron library) I will hold up a red(or other brightly colored) object and upon detecting the red object a 3 second timer will begin and at the end of 3 seconds it will saveFrame().

as it sits now I have it set to saveFrame() based upon the predetermined position of the red object which is not what I want as I stated in the description. So I need help understanding how to set a historical variable from which I can check and compare the position of the red object. Also the "timer" syntax i have set up does not work. It reads it from the start of the program and not based on the if() event.

Question #1  How do set up a historical variable that I can use to compare the current position of the red object to the old position? (when no red object is on screen the draw() repeats the last known position of the red object)  That way I can then then set a Boolean variable of true false to activate saveFrame().

Question #2 How can I get my timer to work like I want it to?  is there a library I can download to get the results I want?

THank you for your help

import JMyron.*;

JMyron m;
boolean foundIt = false;
int xPoint;

void setup(){  
size(640,480);
m = new JMyron();
m.start(640,480);  //sets video window
m.findGlobs(1); //find Globs ON
frameRate(60);
}

void draw(){
//code to generate image START
m.trackColor(255,55,0,150);  //set trackColor to RED
m.update();
int[] img = m.image();  
loadPixels();
for(int i=0;i<width*height;i++){
    pixels[i] = img[i];
}
updatePixels();
//code to generate image END

noFill();
int[][] a;  //set array A

//draw bounding box around RED  object
a = m.globBoxes();
stroke(255,0,0);
for(int i=0;i<a.length;i++){
  int[] b = a[i];
  rect(b[0], b[1], b[2], b[3]);
  xPoint = b[1]; //set variable to be used as a global value
  //for the position of bounding box of red object
}
println(xPoint);

if(xPoint == 250){    
   picture();
   println(foundIt);
   println("Saved Image");  
}
}
public void stop(){
m.stop();
super.stop();
}

void picture(){
int s = millis();
if (s >= 4000) {
  saveFrame("IMadeAPose-####.png");
}
}
Page Index Toggle Pages: 1