【问题标题】:Map Depth to RGB Space将深度映射到 RGB 空间
【发布时间】:2017-04-14 13:48:03
【问题描述】:

我正在使用 KinectPV2 库,该库很棒,但文档记录却很差。

参考下面复制的示例“MapDepthToColor”,我正在尝试检索每个 RGB 像素的深度。

设法调整原始示例以将深度映射到 RGB 空间,我留下了一个奇怪的重复边缘(见左下图)。

有人能指出发生了什么吗?

/*
Thomas Sanchez Lengeling.
<a href="http://codigogenerativo.com/" target="_blank" rel="nofollow">http://codigogenerativo.com/</a>

KinectPV2, Kinect for Windows v2 library for processing

Color to fepth Example,
Color Frame is aligned to the depth frame
*/

import KinectPV2.*;

KinectPV2 kinect;

int [] depthZero;

//BUFFER ARRAY TO CLEAN DE PIXLES
PImage depthToColorImg;

void setup() {
  size(1024, 848, P3D);

  depthToColorImg = createImage(512, 424, PImage.RGB);
  depthZero    = new int[ KinectPV2.WIDTHDepth * KinectPV2.HEIGHTDepth];

  //SET THE ARRAY TO 0s
  for (int i = 0; i < KinectPV2.WIDTHDepth; i++) {
    for (int j = 0; j < KinectPV2.HEIGHTDepth; j++) {
      depthZero[424*i + j] = 0;
    }
  }

  kinect = new KinectPV2(this);
  kinect.enableDepthImg(true);
  kinect.enableColorImg(true);
  kinect.enablePointCloud(true);

  kinect.init();
}

void draw() {
  background(0);

  float [] mapDCT = kinect.getMapDepthToColor(); // Size: 434,176 (512*424)

  //get the raw data from depth and color
  int [] colorRaw = kinect.getRawColor(); // Size: 2,073,600 (1920*1080)

  int [] depthRaw = kinect.getRawDepthData(); // 434176

  //clean de pixels
  PApplet.arrayCopy(depthZero, depthToColorImg.pixels);

  int count = 0;
  depthToColorImg.loadPixels();
  for (int i = 0; i < KinectPV2.WIDTHDepth; i++) {
    for (int j = 0; j < KinectPV2.HEIGHTDepth; j++) {

      //incoming pixels 512 x 424 with position in 1920 x 1080
      float valX = mapDCT[count * 2 + 0];
      float valY = mapDCT[count * 2 + 1];


      //maps the pixels to 512 x 424, not necessary but looks better
      int valXDepth = (int)((valX/1920.0) * 512.0);
      int valYDepth = (int)((valY/1080.0) * 424.0);

      int  valXColor = (int)(valX);
      int  valYColor = (int)(valY);

      if ( valXDepth >= 0 && valXDepth < 512 && valYDepth >= 0 && valYDepth < 424 &&
        valXColor >= 0 && valXColor < 1920 && valYColor >= 0 && valYColor < 1080) {
        float col = map(depthRaw[valYDepth * 512 + valXDepth], 0, 4500, 0, 255);
        //color colorPixel = colorRaw[valYColor * 1920 + valXColor]; // This works as intended
        color colorPixel = color(col); // This doesn't
        depthToColorImg.pixels[valYDepth * 512 + valXDepth] = colorPixel;
      } 
      count++;
    }
  }
  depthToColorImg.updatePixels();

  image(depthToColorImg, 0, 424);
  image(kinect.getColorImage(), 0, 0, 512, 424);
  image(kinect.getDepthImage(), 512, 0);

  text("fps: "+frameRate, 50, 50);
}

【问题讨论】:

  • 我不熟悉这个库,所以只能提供一些猜测:您可能正在以这样一种方式进行迭代,从而错过了这些像素(由于舍入错误)。另外,我认为“深度”这个词有些混乱。在某些地方,您似乎用它来表示宽度:valXDepth &lt; 512,而在其他情况下,它表示与 kinext int [] depthRaw = kinect.getRawDepthData(); 的距离。尝试为您更改内部if ( valXDepth &gt;= 0 &amp;&amp; ... 块以忽略深度数据并仅输出纯色。如果问题出在数据上,您将得到一张纯色图像。
  • ...另一方面,如果您的迭代方式存在问题,则输出应该具有相同的波段。
  • 您能否澄清一下“忽略深度数据”的含义?上面的大部分代码都取自一个示例,因此我仍然不确定kinect.getMapDepthToColor() 究竟返回了什么。我稍微调整了上面的代码,希望能进一步说明问题。当使用colorRaw[] 分配颜色时,它会按预期工作,不像depthRaw[] 会导致复制效果。
  • 问题在于colorRaw[]depthRaw[] 的规模不同。结果似乎非常接近,但我坚持要解决这个问题。
  • 抱歉,我的意思是进行健全性检查...删除您的 if 语句中的所有内容,并将其替换为 ...depthToColorImg.pixels[valYDepth * 512 + valXDepth] = Color.Red; 或类似内容。然后运行您的代码并验证输出图像是否为纯色。目的是确认这不是定位/舍入错误,但看起来您已经消除了这种可能性。抱歉,如果没有 kinect,我将无能为力。

标签: java processing kinect


【解决方案1】:

我在这里发布了这个问题的解决方案:https://forum.processing.org/two/discussion/comment/95494#Comment_95494

【讨论】:

    猜你喜欢
    • 2016-04-27
    • 1970-01-01
    • 1970-01-01
    • 2012-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多