【发布时间】: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