processing - 处理 Kinect (v2) 图像中间的奇怪点

标签 processing kinect openkinect

我正在尝试使用 Processing 为基本的 Kinect (v2) 深度云调整 Daniel Shiffman 的代码,但是屏幕中间总是有一个像素不会去任何地方,这很烦人。这是我的意思的一个例子。
enter image description here
您可以看到它似乎就在前面,并且在视野中的任何物体移动时都不会移动。
这是我用来生成上面图像的代码,(这是我正在尝试做的非常精简的版本)

// 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;
}
有谁知道这个点是从哪里来的,我该如何摆脱它?

最佳答案

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

if (d == 0){
    continue;
} 
在它计算了当前像素的深度之后,效果很好。我想我会回答我自己的问题,以防其他人遇到类似的问题。
我知道它仍然潜伏在数据中,所以如果有人知道问题的根源,我仍然想知道它为什么会发生 - 我对处理语言很陌生,所以我确定有只是我缺少的东西。
但就目前而言,至少它是“固定的”!

关于processing - 处理 Kinect (v2) 图像中间的奇怪点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65361454/

相关文章:

algorithm - 计算深度图像中像素与相机平面的角度

kinect - 在 Windows 10 Mobile 中访问 IR/虹膜扫描仪/Windows hello 设备

java - 我需要帮助在 java 平台游戏中创建碰撞系统

processing - 在处理 JS 中使用带有选项卡的处理草图

java - JFrame 的组件仅在调整大小后才位于正确的位置(有时)

c - C 语言(也称为非 C++)的 Kinect 和 OpenNI 示例代码

java - android : AssetManager and list() not working 处理

c# - 在 WPF 中设置鼠标位置

node.js - Node.js 和 Kinect 如何通信?

opencv - 无法在 Ubuntu 平台上使用 Opencv 和 libfreenect 驱动程序访问 Kinect 传感器摄像头