Image swipe by blob detection using flob..
in
Contributed Library Questions
•
3 years ago
Hi,
Im totally new to processing so some of my questions might be very very trivial so please forgive that. Im currently using the flob library. What I wish to achieve is to have an image swipe across based on the movement of my hand as captured by the webcam. So I suppose Ive got to extract the largest blob and reposition the image to the position of the largest blob. Ive played around with the examples in flob and am trying to modify the code to suit my needs but it dosent exactly work. Can someone please help me out..Thanks :-)
Here's the code:
- 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[];
- PImage b;
- float maxArea = 0;
- float xPos = 0, yPos = 0;
- float area = 0;
- 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[1], fps);
- flob = new Flob(video, width, height);
- flob.setMirror(true,false);
- flob.setThresh(12);
- flob.setFade(25 );
- flob.setMinNumPixels(100);
- flob.setImage( vtex );
- //PImage b;
- b = loadImage("dummy.jpg");
- image(b,0,0);
- //bolas = new Bola[10];
- //for(int i=0;i<bolas.length;i++){
- //bolas[i] = new Bola();
- // }
- textFont(font);
- }
- void draw(){
- background(102);
- 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) );
- }
- //background(102);
- //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);
- area = tb.dimx * tb.dimy;
- if(area > maxArea){
- maxArea = area;
- xPos = tb.cx;
- yPos = tb.cy;
- }
- 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);
- }
- image(b,xPos,yPos);
- /* 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);
- }
- */
- }
Thanks a lot..
1