Trying to get blob detection to work with kinect

edited November 2013 in Kinect

I'm fairly new to the whole processing, kinect thing and was wondering how to get blob detection to work for the kinect. I want to do an interactive thing where every blob is recognized separately so I can then give an animation, action, or sound to each one. I've downloaded the blobdetection library but can't figure out how to change it from webcam to kinect. I also have the openNI library. This is what I have so far...since I'm changing the code around, I got stuck because I get an error saying it can't find the 'cam'. Is this the correct direction? Please help!

//import processing.video.*;//
import blobDetection.*;


import SimpleOpenNI.*;
SimpleOpenNI kinect;

//Capture cam;//
BlobDetection theBlobDetection;
PImage img;
boolean newFrame=false;

// ==================================================
// setup()
// ==================================================
void setup()
{
    size(640*2, 480);
  kinect = new SimpleOpenNI(this);
  kinect.enableDepth();  

    // BlobDetection
    // img which will be sent to detection (a smaller copy of the cam frame);
    img = new PImage(80,60); 
    theBlobDetection = new BlobDetection(img.width, img.height);
    theBlobDetection.setPosDiscrimination(true);
    theBlobDetection.setThreshold(0.2f); // will detect bright areas whose luminosity > 0.2f;
}

// ==================================================
// draw()
// ==================================================
void draw()
{
    if (newFrame)
    {
        newFrame=false;
        image(cam,0,0,width,height);
        img.copy(cam, 0, 0, cam.width, cam.height, 
                0, 0, img.width, img.height);
        fastblur(img, 2);
        theBlobDetection.computeBlobs(img.pixels);
        drawBlobsAndEdges(true,true);
    }
}

Thanks!!

Answers

  • edited November 2013 Answer ✓

    You're not updating in your draw() method:

    void draw(){
    kinect.update();
    

    then you need to pull the rgbImage() from the kinect, ie:

    PImage userImage = kinect.rgbImage();
    image(userImage, 0, 0);
    

    then do all your img.copy(userImage, 0, 0...etc after that.

    Get rid of the if(newFrame){ newFrame=falsecode. It looks like you pulled that from the webcam demo. Get rid of it, as you're using the SimpleOpenNI object to access the kinect now, instead of whatever leftover code you had from the cam sample.

  • Thanks for your response!

    However, when I changed the code, I now get a Nullerpoint exception at the

    image(userImage, 0, 0);
    

    would you know why?

  • edited November 2013

    Have you declared userImage?

    ie: PImage userImage; as above. When you do that, make sure the variable scope is appropriate as well. If you are, and it's correctly in scope, then the problem is likely that that camera itself isn't initialized OR you're not declaring kinect.enableRGB(); in your setup() method.

  • AMore, Have your resolved the problem? Do you have the resolved code available?

Sign In or Register to comment.