【问题标题】:Kinect Depth Histogram in Processing处理中的 Kinect 深度直方图
【发布时间】:2015-03-26 16:17:05
【问题描述】:

我正在尝试创建一个直方图,显示 Kinect 扫描的距离与其出现的距离。我已经调整了直方图示例代码来创建深度直方图,但它目前在深度图像宽度上多次显示每个像素(从左到右)的深度。 我要做的是重新排序深度信息,使其范围从 x 轴上的最低值(不是 0)到最高值,并在 y 上显示它们的出现。我正在使用处理,所以我不确定这是否是正确的发布网站,但我已经在发布论坛上尝试过,但没有得到任何帮助。如果有人能告诉我哪里出错了,那就太棒了。我当前的代码如下,可以找到我当前输出的截图here

    import SimpleOpenNI.*;

    SimpleOpenNI kinect;

    void setup() {
      size(1200, 580);

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

    void draw () {
      kinect.update();
      PImage depthImage = kinect.depthImage();
      image (depthImage, 11, 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(20);
      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);
      }
    }

【问题讨论】:

    标签: processing kinect histogram


    【解决方案1】:

    我想你在这里问了两个问题。

    如何让直方图从 0 到 N:
    使用 Processing 的 sort() function 对数组进行排序。

    hist = sort(hist);  // sorts your array numerically
    

    如何让直方图填满屏幕:
    我不完全确定它为什么要绘制两次,但我认为您可以清理一下代码。

    // how far apart are the bars - set based on screen dimensions
    int barSpacing = width / hist.length; 
    
    for (int i=0; i<hist.length; i++) {
    
      // get value and map into usable range (note 10 not 0 for min)
      int h = int(map(hist[i], 0,histMax, 10,height)); 
    
      // set x position onscreen
      int x = i * barSpacing;
    
      // draw the bar
      line(x,height, x,height-h);
    }
    

    【讨论】:

    • 您好,我之前尝试过使用 sort 功能,但没有得到太多运气。刚刚尝试了您的方法,结果输出是深度图像,每隔几秒显示一帧,并且在深度图像的左侧有一条细线。我认为问题可能是由于 Kinect 不断扫描新的深度值,直方图数据不断刷新。你知道我如何捕捉一帧的价值吗?感谢您的帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-03
    • 1970-01-01
    • 1970-01-01
    • 2021-03-26
    • 2014-11-17
    • 1970-01-01
    相关资源
    最近更新 更多