sorting blobs?
in
Contributed Library Questions
•
1 year ago
Hi,
I have code for use with the Kinect which I have merged with some blob tracking from blobscanner.
I want to track only the biggest blob (which will, in practice be a person's whole body) and find where it moves. I don't know how to sort the blobs, though, and talk only to the biggest one.
I want to track only the biggest blob (which will, in practice be a person's whole body) and find where it moves. I don't know how to sort the blobs, though, and talk only to the biggest one.
Any ideas?
Thanks in advance!
- //---------------------------------------------
- //Thanks to thomas diewald for dLibs processing library for Kinect
- //Antonio Molinaro for blobscanner library
- import Blobscanner.*;
- //freenect stuff
- import dLibs.freenect.toolbox.*;
- import dLibs.freenect.constants.*;
- import dLibs.freenect.interfaces.*;
- import dLibs.freenect.*;
- //-----------------------KINECT STUFF-------------------------------------
- Kinect kinect_;
- KinectFrameVideo kinect_video_;
- KinectFrameDepth kinect_depth_;
- int kinectFrame_size_x = VIDEO_FORMAT._RGB_.getWidth();
- int kinectFrame_size_y = VIDEO_FORMAT._RGB_.getHeight();
- PImage video_frame_, depth_frame_; // images
- // raw depth values of the kinect depth camera ( copy by reference or deep copy)
- int[] raw_depth;
- int tooFar, tooClose;
- float biggestBlobX, biggestBlobY;
- boolean reaching = false;
- //----------------------------------------------------------------------------
- //-----------------------BLOB SCANNER STUFF-----------------------------------
- Detector bd;
- PImage img;
- PFont f = createFont("", 10);
- //-----------------------------------------------------------------------------
- void setup(){
- size(kinectFrame_size_x, kinectFrame_size_y*2);
- kinect_ = new Kinect(0);
- kinect_video_ = new KinectFrameVideo(VIDEO_FORMAT._RGB_ );
- kinect_depth_ = new KinectFrameDepth(DEPTH_FORMAT._11BIT_);
- kinect_depth_.setColorMode(2); // no generation of depth-map by default
- kinect_video_.setFrameRate(30);
- kinect_depth_.setFrameRate(30);
- kinect_video_.connect(kinect_);
- kinect_depth_.connect(kinect_);
- // create a PImage for video/depth
- video_frame_ = createImage(VIDEO_FORMAT._RGB_ .getWidth(), VIDEO_FORMAT._RGB_ .getHeight(), RGB);
- depth_frame_ = createImage(DEPTH_FORMAT._11BIT_.getWidth(), DEPTH_FORMAT._11BIT_.getHeight(), RGB);
- // hint: allocate the arraysize, if the values should be copied for every frame (deep copy)
- //raw_depth = new int[depth_frame_.pixels.length];
- //blob detection
- bd = new Detector( this, 0, 0, kinectFrame_size_x, kinectFrame_size_y, 255 );
- }
- //-------------------------------------------------------------------
- void draw(){
- background(0);
- // println(frameRate);
- //---------------------------------------
- // DEPTH VALUES
- //---------------------------------------
- raw_depth = kinect_depth_.getRawDepth(); // just copy by reference
- // custom mapping from raw-depth values, to a gray depthmap
- depth_frame_.loadPixels();
- for (int i = 0; i < raw_depth.length; i++){
- // 2047 is the depth-value-"code" for kinect-shadows
- /*if
- ( raw_depth[i] == 2047) {
- // set blue color for shadows, ... or any other color
- depth_frame_.pixels[i] = 0xFF0000AA;
- } else
- { */ // valid depth values
- // raw depth values have a range of ~330 to ~1150 and are mapped to a gray-values from 255 to 0
- //int gray = ((int) map(raw_depth[i], 330, 1150, 255, 0)) & 0xFF ;
- if(raw_depth[i] > 350 && raw_depth[i] < 720 ){
- depth_frame_.pixels[i] = 0xFF0000;
- }
- else{
- depth_frame_.pixels[i] = 0x000000;
- }
- }
- //FLAG if anyone reaches ahead
- depth_frame_.updatePixels();
- //---------------------------------------
- // VIDEO VALUES
- //---------------------------------------
- // copy rgb-video-pixels to image (by reference!!)
- video_frame_.loadPixels();
- video_frame_.pixels = kinect_video_.getPixels();
- video_frame_.updatePixels();
- //set up blobtracker thresholding of image
- image(depth_frame_, 0, 0);
- //image(depth_frame_, 0, DEPTH_FORMAT._11BIT_.getHeight());
- bd.imageFindBlobs(depth_frame_);
- bd.loadBlobsFeatures();
- //Draws the bounding box for all the blobs in the image.
- bd.drawBox(color(0, 100, 255),1);
- }
- void dispose(){
- Kinect.shutDown();
- super.dispose();
- }
1