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.
IndexProgramming Questions & HelpVideo Capture,  Movie Playback,  Vision Libraries › Combining Flob Tracking With Mouse Trails
Page Index Toggle Pages: 1
Combining Flob Tracking With Mouse Trails? (Read 1184 times)
Combining Flob Tracking With Mouse Trails?
Mar 12th, 2010, 2:58am
 
Hi guys, Im very new to Processing and was just wondering if there is a way to combine the Flob Collide example with a simple mouse trail? The Flob collide allows you to push sprites off the screen using body movement but I was wondering if there was a way for a trail to emit behind the sprites as they leave the screen (like some of the mouse trail examples)? Below are the sperate files Im working with but I cant seem to combine them together? Thanks for your help, Im struggling with the language so far and cant seem to figure it out.

flob_calcsimple_collide:


import processing.opengl.*;
import processing.video.*;
import s373.flob.*;

Capture video;
Flob flob;


int videores=128;
int fps = 60;
PFont font = createFont("arial",10);

Bola bolas[];

boolean showcamera=true;
boolean om=true,omset=false;
float velmult = 10000.0f;
int vtex=0;


void setup(){
 //bug 882 processing 1.0.1
 try {
   quicktime.QTSession.open();
 }
 catch (quicktime.QTException qte) {
   qte.printStackTrace();
 }

 size(640,480,OPENGL);
 frameRate(fps);

 String[] devices = Capture.list();
 println(devices);

 video = new Capture(this, videores, videores,  devices[4], fps);  
 flob = new Flob(this, video, width, height);
 flob.setMirror(true,false);
 flob.setThresh(12);//25);//16);
 flob.setFade(25);//2);//10);
 flob.setMinNumPixels(10);
 flob.setImage( vtex );

 bolas = new Bola[10];
 for(int i=0;i<bolas.length;i++){
   bolas[i] = new Bola();
 }

 textFont(font);
}


void draw(){
 if(video.available()) {  
   if(!omset){
     if(om)
       flob.setOm(flob.CONTINUOUS_DIFFERENCE);
     else
       flob.setOm(flob.STATIC_DIFFERENCE);
     omset=true;
   }
   video.read();

   // aqui é que se define o método calc, calcsimple, ou tracksimple
   // o tracksimple é mais preciso mas mais pesado que o calcsimple

   //    flob.tracksimple(  flob.binarize(video) );
   flob.calcsimple(  flob.binarize(video) );
 }

 image(flob.getSrcImage(), 0, 0, width, height);

 //report presence graphically
 fill(255,152,255);
 rect(0,0,flob.getPresencef()*width,10);

 fill(255,100);
 stroke(255,200);
 //get and use the data
 // int numblobs = flob.getNumBlobs();
 int numtrackedblobs = flob.getNumTrackedBlobs();

 text("numblobs> "+numtrackedblobs,5,height-10);

 fill(255,10);
 rectMode(CENTER);
 stroke(127,200);

 trackedBlob tb;

 for(int i = 0; i < numtrackedblobs; i++) {
   tb = flob.getTrackedBlob(i);
   rect(tb.cx, tb.cy, tb.dimx, tb.dimy );
   line(tb.cx, tb.cy, tb.cx + tb.velx * velmult ,tb.cy + tb.vely * velmult );    
   String txt = ""+tb.id+" "+tb.cx+" "+tb.cy;
   text(txt,tb.cx, tb.cy);
 }

 // colisão

 float cdata[] = new float[5];
 for(int i=0;i<bolas.length;i++){
   float x = bolas[i].x / (float) width;
   float y = bolas[i].y / (float) height;
   cdata = flob.imageblobs.postcollidetrackedblobs(x,y,bolas[i].rad/(float)width);
   if(cdata[0] > 0) {
     bolas[i].toca=true;
     bolas[i].vx +=cdata[1]*width*0.015;
     bolas[i].vy +=cdata[2]*height*0.015;
   }
   else {
     bolas[i].toca=false;
   }
   bolas[i].run();
 }

 if(showcamera){
   tint(255,150);
   image(flob.videoimg,width-videores,height-videores);
   image(flob.videotexbin,width-2*videores,height-videores);
   image(flob.videotexmotion,width-3*videores,height-videores);
 }

}

void keyPressed(){
 if(key==' ')
   flob.setBackground(video);
 if(key=='o'){
   om^=true;
   omset=false;
 }
 if(key=='i')
   showcamera^=true;
 if(key=='v'){
   vtex = (vtex + 1) % 4;
   flob.setVideoTex(  vtex  );
 }
}







bola:


class Bola
{

 float x,y,vx,vy;
 float g = 0.025, rad= random(5,25);
 boolean toca=false;
 Bola(){
   init();  
 }
 void init(){
   vx = random(-1.1,1.1);
   vy = random(1.5);
   x = random(width);
   y = random(-100,-50);      
 }
 void update(){
   // vy+=g;
   // vx+=g;
   x+=vx;
   y+=vy;

   if(abs(vx)>3)
     vx*=0.9;
   if(abs(vy)>3)
     vy*=0.9;

   if(x<-rad){
     x=-rad;
     vx = -vx;
   }
   if(x>width+rad){
     x=width+rad;
     vx = -vx;
   }
   if(y<-100){
     y=-100;
     vy = -vy;
   }
   if(y>height-rad){
     y=height-rad;
     vy = -vy;
   }


 }
 void draw(){
   if(!toca)
     fill(0,255,0);
   else
     fill(255,0,0);
   ellipse(x,y,rad*2,rad*2);
 }
 void run(){
   update();
   draw();
 }
}







linedraw:


void setup() {
      size(800, 600);

    }

void draw() {
 
 size(800,600);

 fill(0,1); // use black with alpha 10

 rectMode(CORNER);

 rect(0,0,800,600);



 // draw some stuff, for example simple mouse trails

 stroke(255);

 line(pmouseX,pmouseY,mouseX,mouseY);

}
Re: Combining Flob Tracking With Mouse Trails?
Reply #1 - Mar 15th, 2010, 1:52am
 
Does anyone have any ideas guys? Im totally clueless here!
Re: Combining Flob Tracking With Mouse Trails?
Reply #2 - Mar 15th, 2010, 2:10pm
 
hi

your problem is trying to combine graphics that erase background, with graphics which dont.

one solution is to add many previous positions to each ball and draw all previous positions. i attach a simple fifo addition to the bolas class, which may get you started. notice and change the trails pvector array

hth,

a


class Bola
{
 float x,y,vx,vy;
 float g = 0.025, rad= random(5,25);
 boolean toca=false;
 PVector trails[] = new PVector[500];
 Bola(){

   init();  
   
   for(int i=0;i<trails.length;i++)
     trails[i] = new PVector(x,y,0);
 }
 void init(){
   vx = random(-1.1,1.1);
   vy = random(1.5);
   x = random(width);
   y = random(-100,-50);      
 }
 void update(){
   // vy+=g;
   // vx+=g;
   x+=vx;
   y+=vy;
   
   for(int i=trails.length-2;i>=0;i--)
     trails[i+1].set(trails[i]);
   trails[0].set(x,y,0);

   if(abs(vx)>3)
     vx*=0.9;
   if(abs(vy)>3)
     vy*=0.9;

   if(x<-rad){
     x=-rad;
     vx = -vx;
   }
   if(x>width+rad){
     x=width+rad;
     vx = -vx;
   }
   if(y<-100){
     y=-100;
     vy = -vy;
   }
   if(y>height-rad){
     y=height-rad;
     vy = -vy;
   }


 }
 void draw(){
   if(!toca)
     fill(0,255,0);
   else
     fill(255,0,0);
   ellipse(x,y,rad*2,rad*2);
   
   for(int i=0;i<trails.length-1;i++)
     line(trails[i].x,trails[i].y, trails[i+1].x,trails[i+1].y);
 }
 void run(){
   update();
   draw();
 }
}


Re: Combining Flob Tracking With Mouse Trails?
Reply #3 - Mar 16th, 2010, 2:52am
 
Thanks AS thats exactly what I wanted. Cheers!
Page Index Toggle Pages: 1