如何在 MATLAB 中从 3D 点云中提取 xyz 坐标

How to extract xyz coordinates from 3D point cloud in MATLAB

我正在使用 Windows 的 Kinect 将 3D 图像导入 MATLAB。我希望能够在 3D 场景中找到对象的 3D 坐标。

一个简单的方法是使用 clickA3DPoint 函数找到 here,然后单击我想知道坐标的点。

问题是 clickA3DPoint 需要 3 by N 矩阵中的参数,即 x yz 坐标 N 样本。当我使用 Kinect 获得点云 depthToPointCloud 它 returns 一个 480 * 640 * 3 矩阵。

如何从此矩阵中提取 x、y 和 z 坐标,以便用 clickA3DPoint 绘制它? (或scatter3?)

我目前的尝试:

depthDevice = imaq.VideoDevice('kinect',2)  %this is the kinect depth sensor

depthImage = step(depthDevice);  %this takes a depth image. (A 480 * 640 uint16 array)

xyzPoints = depthToPointCloud(depthImage,depthDevice); %convert the depth image to a point cloud

clickA3DPoint(reshape(xyzPoints,[3,307200])) %I'm guessing each of the 480 * 640 points (307200 points) has an x,y and z coordinate, so this concates the coordinates of all these points.

但这只是在 3D space 中沿着对角线绘制点。我如何从 Matlab 中的点云中实际提取 x、y 和 z 坐标?

您可以使用 pcshow 函数绘制您的点,它将直接采用 M×N×3 数组。然后您可以打开 data tips 并单击绘图中的点以查看它们的坐标。

如果您仍想创建一个 3×N 矩阵,那么最简单的方法如下:

x = xyzPoints(:,:,1);
y = xyzPoints(:,:,2);
z = zyzPoints(:,:,3);
points3D = [x(:)'; y(:)', z(:)'];

你可以使用pointCloud的属性 'Location'来获取x,y,z。 例如:

moving = movingReg.Location;%movingReg is a pointCloud
scatter(moving(:,1),moving(:,2));