Send out Blobs via Syphon
              in 
             Integration and Hardware 
              •  
              4 months ago    
            
 
           
             How can I correctly wrap just the Blob parts of this sketch to send out via Syphon?
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
            
            
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
                
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
              
             
             
                
             
             
              
             
             
              
             
             
              
             
             
            
             
            
            
             
            
            
             
             
           
 
            
           
             This sketch takes in the Kinect clean IR, filters it, and then draws Blobs on top. I want to send out just the Blobs via syphon.
            
            
             At first I gathered that the blobs are not images but shapes, so you must collect them into one scene (PGraphics?) so that Syphon can take this feed and send it out. However I was only able to send out a blank syphon feed, it did not seem to correctly gather all of the blobs if I put a canvas.beginDraw(); above and a canvas.endDraw(); below the blob code.
            
            
             How do I correctly send out just the Blob part?
            
            
             Thanks for any suggestions,
            
            
             ----------
            
            
              import SimpleOpenNI.*;
             
             
              import hypermedia.video.*;
             
             
              import java.awt.Rectangle;
             
             
              import java.awt.Point;
             
             
              import codeanticode.syphon.*;
             
             
              PGraphics canvas;
             
             
              SyphonServer server;
             
             
              SimpleOpenNI  kinectLib;
             
             
              OpenCV opencv;
             
             
              int cvthreshold = 80;
             
             
              int blur = 5;
             
             
              void setup() {
             
             
                size(640, 480, P3D);
             
             
                canvas = createGraphics(640,480,P3D);
             
             
                kinectLib = new SimpleOpenNI(this);
             
             
                opencv = new OpenCV(this);
             
             
                opencv.allocate(640, 480);
             
             
                server = new SyphonServer(this, "BlobsOut");
             
             
                if (kinectLib.enableIR() == false) {
             
             
                  println(" can't open IR ");
             
             
                  exit();
             
             
                  return;
             
             
                }
             
             
              }
             
             
              void draw() {
             
             
                kinectLib.update();
             
             
                background(122);
             
             
                // copy the RGB image into opencv
             
             
                opencv.copy(kinectLib.irImage(), 0, 0, 640, 480, 0, 0, 640, 480);
             
             
                opencv.absDiff();
             
             
                opencv.blur( OpenCV.BLUR, blur );
             
             
                opencv.threshold(cvthreshold);
             
             
                image(opencv.image(), 0, 0, 640, 480);
             
             
                // This generates the blobs
             
             
                Blob[] blobs = opencv.blobs( 20, width*height/100, 20, true );
             
             
                noFill();
             
             
                pushMatrix();
             
             
                translate(0, 0);
             
             
                for ( int i=0; i<blobs.length; i++ ) {
             
             
                  Rectangle bounding_rect  = blobs[i].rectangle;
             
             
                  float area = blobs[i].area;
             
             
                  float circumference = blobs[i].length;
             
             
                  Point centroid = blobs[i].centroid;
             
             
                  Point[] points = blobs[i].points;
             
             
                  // rectangle
             
             
                  noFill();
             
             
                  stroke( blobs[i].isHole ? 128 : 64 );
             
             
                  rect( bounding_rect.x, bounding_rect.y, bounding_rect.width, bounding_rect.height );
             
             
                  // centroid
             
             
                  stroke(0, 0, 255);
             
             
                  line( centroid.x-5, centroid.y, centroid.x+5, centroid.y );
             
             
                  line( centroid.x, centroid.y-5, centroid.x, centroid.y+5 );
             
             
                  noStroke();
             
             
                  fill(0, 0, 255);
             
             
                  text( area, centroid.x+5, centroid.y+5 );
             
             
                  fill(255, 0, 255, 64);
             
             
                  stroke(255, 0, 255);
             
             
                  if ( points.length>0 ) {
             
             
                    beginShape();
             
             
                    for ( int j=0; j<points.length; j++ ) {
             
             
                      vertex( points[j].x, points[j].y );
             
             
                    }
             
             
                    endShape(CLOSE);
             
             
                  }
             
             
                  noStroke();
             
             
                  fill(255, 0, 255);
             
             
                  text( circumference, centroid.x+5, centroid.y+15 );
             
             
                }
             
             
                popMatrix();
             
             
              }
             
             
              void keyPressed() {
             
             
                opencv.copy(kinectLib.irImage(), 0, 0, 640, 480, 0, 0, 640, 480);
             
             
                opencv.threshold(80);
             
             
                opencv.remember(OpenCV.BUFFER);
             
             
              }
             
             
              //This allows you to use the mouse the adjust blur and threshold
             
             
              void mouseDragged() {
             
             
                cvthreshold = int( map(mouseX, 0, width, 0, 255) );
             
             
                blur = int( map(mouseY, 0, height, 50, 0) );
             
             
              }
             
            
             -----------
            
             
              
              1  
            
 
            