【问题标题】:Weird dot in middle of Processing Kinect (v2) image处理 Kinect (v2) 图像中间的奇怪点
【发布时间】:2020-12-18 17:34:55
【问题描述】:

我正在尝试使用 Processing 将 Daniel Shiffman 的代码改编为基本的 Kinect (v2) 深度云,但屏幕中间总是有一个像素不会去任何地方,这很烦人。这是我的意思的一个例子。

您可以看到它似乎就在前面,并且当视野中的任何东西移动时它都不会移动。

这是我用来生成上面图像的代码,(这是我正在尝试做的一个非常精简的版本)

// imports for openkinect
import org.openkinect.freenect2.*;
import org.openkinect.processing.*;
import java.nio.FloatBuffer;

// dots size is dot_size*skip
int dot_size = 2;

// step size when iterating through pixel array
int skip = 5; 

// Kinect Library object
Kinect2 kinect2;

// Angle for rotation
float a = 3.1;

void setup() {
  // Rendering in P3D
  size(1500,1000,P3D);

  // start the kinect
  kinect2 = new Kinect2(this);
  kinect2.initDepth();
  kinect2.initDevice();

  smooth(16);
  
  // Black background
  background(0);
  
}

void draw() {
  background(0);
  
  // Translate and rotate
  pushMatrix();
  translate(width/2, height/2,50);
  rotateY(a);
  
  // get current depth information
  int[] depth = kinect2.getRawDepth();
  
  // read depth pixels in kinect window bounds
  for (int x = 0; x < kinect2.depthWidth; x+=skip) {
    for (int y = 0; y < kinect2.depthHeight; y+=skip) {
      
      // compute offset for 1D depth array
      int offset = x + y * kinect2.depthWidth;
      
      // get the depth
      int d = depth[offset];
      
      //calculte the x, y, z camera position based on the depth information
      PVector point = depthToPointCloudPos(x, y, d);
      
      // compute depth modifier for colours and such
      float depth_modifier = map(point.z,1000,2048,255,0);
      
      fill(depth_modifier);
      
      pushMatrix();
      translate(point.x,point.y,point.z);
      circle(0,0,skip*dot_size);
      popMatrix();
    }
  }
   
  popMatrix();
}

//calculte the xyz camera position based on the depth data
PVector depthToPointCloudPos(int x, int y, float depthValue) {
  PVector point = new PVector();
  point.z = (depthValue);// / (1.0f); // Convert from mm to meters
  point.x = (x - CameraParams.cx) * point.z / CameraParams.fx;
  point.y = (y - CameraParams.cy) * point.z / CameraParams.fy;
  return point;
}

这是CameraParams.pde 的内容,方便他人复制:

//camera information based on the Kinect v2 hardware
static class CameraParams {
  static float cx = 254.878f;
  static float cy = 205.395f;
  static float fx = 365.456f;
  static float fy = 365.456f;
  static float k1 = 0.0905474;
  static float k2 = -0.26819;
  static float k3 = 0.0950862;
  static float p1 = 0.0;
  static float p2 = 0.0;
}

有谁知道这个点是从哪里来的,我该如何摆脱它?

【问题讨论】:

  • 回到我探索kinect深度数据的时候,我把帧导出到Excel中,一目了然地分析。然后,我会将单元格调整为正方形,并根据它们的深度数据自动为它们着色。查看该点附近的数据可以帮助您确定它是来自数据流中的工件还是来自其他东西。
  • 要在 excel 中导出,我会写在 CSV 样式的文件中,然后从 excel 中导入。

标签: processing kinect openkinect


【解决方案1】:

我设法修复了它,这是一个有点老套的解决方案,但它起作用了.. 像素似乎正好显示在 0 深度,所以我只是添加了代码:

if (d == 0){
    continue;
} 

在它计算出当前像素的深度之后,效果很好。我想我会回答我自己的问题,以防其他人有类似的问题。

我知道它仍然潜伏在数据中,所以如果有人知道问题的根源,我仍然想知道它为什么会发生 - 我对处理语言很陌生,所以我确定我缺少一些东西。

但就目前而言,至少它是“固定的”!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-29
    • 1970-01-01
    • 1970-01-01
    • 2015-05-21
    相关资源
    最近更新 更多