I want to track motion with jMyron to add some MSAFluid when things move. But I want the background to be a standard webcam output.
I was going to do this by placing a webcam feed over the top of the motion tracker, then layering the MSAFluid over the top of that.
Any ideas towards this would be great.
Currently it runs like this and looks terrible ..
- import com.nootropic.processing.layers.*;
- import JMyron.*;
- JMyron onScreen;
- int[] currFrame;
- int[] prevFrame;
- int tolerance;
- boolean revealing;
- AppletLayers layers;
- void setup() {
- size(640,480);
- onScreen = new JMyron();
- onScreen.start(width, height);
- onScreen.findGlobs(0);
- // initialize the pixel arrays to avoid a NullPointerException
- loadPixels();
- currFrame = prevFrame = pixels;
- tolerance = 50;
- revealing = true;
- }
- void draw()
- {
- // erase the previous image
- onScreen.update();
- // save the last frame before updating it
- prevFrame = currFrame;
- currFrame = onScreen.image();
- // draw each pixel to the screen only if its change factor is
- // higher than the tolerance value
- loadPixels();
- for (int i=0; i < width*height; i++)
- {
- if (comparePixels(i))
- {
- pixels[i] = currFrame[i];
- }
- }
- updatePixels();
- }
- boolean comparePixels(int index)
- {
- if (Math.abs(red(currFrame[index])-red(prevFrame[index])) < tolerance)
- if (Math.abs(green(currFrame[index])-green(prevFrame[index])) < tolerance)
- if (Math.abs(blue(currFrame[index])-blue(prevFrame[index])) < tolerance)
- return !revealing;
- return revealing;
- }
- void keyReleased()
- {
- if (key == '.' || key == '>')
- {
- // increase tolerance
- tolerance += 2;
- println("Tolerance at " + tolerance);
- }
- else if (key == ',' || key == '<')
- {
- // decrease tolerance
- tolerance -= 2;
- println("Tolerance at " + tolerance);
- // toggle the revealing mode
- }
- else if (key == ' ')
- {
- revealing = !revealing;
- }
- }
- public void stop() {
- onScreen.stop();
- super.stop();
- }
1