Depth Histogram

Hi, I'm trying to create a histogram displaying the distances scanned by a Kinect vs. their occurrences. I've adapted the Histogram example code to create a depth histogram, but it's currently displaying the depth at each pixel (from left to right) multiple times across the depth image width. What I'm looking to do is reorder the depth information so that it ranges from the lowest value (that isn't 0) to the highest on the x axis, and shows their occurrences on the y. If anyone can show me where I'm going wrong, that'd be awesome. My current code is below, and a screenshot of my current output can be found here

    import SimpleOpenNI.*;

    SimpleOpenNI kinect;

    void setup() {
      size(640, 480);

      kinect = new SimpleOpenNI(this);
      kinect.enableDepth();
    }

    void draw () {
      kinect.update();
      PImage depthImage = kinect.depthImage();
      image (depthImage, 0, 0);

      int[] depthValues = kinect.depthMap();
      int[] hist = new int[716800];

      for (int x = 11; x < depthImage.width; x++) {
        for (int y = 0; y < depthImage.height; y++) {
          int i = x + y * 640;
          hist[i] = depthValues[i];
        }
      }

      int histMax = max(hist);

      stroke(255);
      for (int i = 0; i < depthImage.width; i += 2) {
        int which = int(map(i, 0, depthImage.width, 0, histMax));
        int y = int(map(hist[which], 0, histMax, depthImage.height, 0));
        line(i, depthImage.height, i, y);
      }
    }
Tagged:

Answers

  • Hello !

    I'm not sure but I don't understand your line

    int y = int(map(hist[which], 0, histMax, depthImage.height, 0));

    I think you would like to write

    int y = int(map(which, 0, histMax, depthImage.height, 0));

  • Hi! Changed that and it just comes out with a perfectly linear slope from the bottom left to top right of the screen. I think the next step should be to try and reorder the hist array and then mapping it.

Sign In or Register to comment.