Advertisement
orgicus

SimpleOpenNI Blobs

Apr 29th, 2013
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. import hypermedia.video.*;
  2. import SimpleOpenNI.*;
  3.  
  4. SimpleOpenNI ni;
  5. OpenCV cv;
  6.  
  7. void setup(){
  8.   size(640,480);stroke(0,192,0);//basic setup
  9.   ni = new SimpleOpenNI(this);
  10.   if(SimpleOpenNI.deviceCount() == 0) ni.openFileRecording("/Users/hm/Documents/Processing/tests/OpenNIPoseRecorder/data/20Apr2013-16.07.oni");
  11.   ni.enableDepth();
  12.   cv = new OpenCV(this);
  13.   cv.allocate(width,height);//tell OpenCV to allocate memory for the pixels we'll use from the depth sensor
  14. }
  15. void draw(){
  16.   //update
  17.   ni.update();
  18.   cv.copy(ni.depthImage());//copy data from depth sensor to opencv
  19.   cv.blur(BLUR,((int)map(mouseY,0,height,0,4)*2)+1);//optionally smooth/blur a bit: blur value should be odd (1, 3, 5, …), so that a pixel neighborhood used for smoothing operation is symmetrical relative to the pixel.
  20.   cv.threshold(map(mouseX,0,width,0,255));//threshold
  21.   Blob[] blobs = cv.blobs( 10, width*height/2, 100, true, OpenCV.MAX_VERTICES*4 );
  22.   //draw
  23.   image(cv.image(),0,0);//threshold result
  24.   for( int i=0; i<blobs.length; i++ ) {//blobs
  25.     beginShape();
  26.     for( int j=0; j<blobs[i].points.length; j++ )
  27.       vertex( blobs[i].points[j].x, blobs[i].points[j].y );
  28.     endShape(CLOSE);
  29.   }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement