[英]How to extract xyz coordinates from 3D point cloud in MATLAB
I am using a Kinect for Windows to import 3D images into MATLAB. 我正在使用Kinect for Windows将3D图像导入MATLAB。 I want to be able to find the 3D co-ordinates of objects within the 3D scene. 我希望能够在3D场景中找到对象的3D坐标。
One simple way to do this is to use the clickA3DPoint
function found here , and then click the point I want to know the co-ordinates of. 一个简单的方法是使用此处找到的clickA3DPoint
函数,然后单击我想知道坐标的点。
The problem is clickA3DPoint
expects the arguments in a 3 by N
matrix, which is the x
y
and z
coordinates of N
samples. 问题是clickA3DPoint
需要3 by N
矩阵的参数,即N
样本的x
y
和z
坐标。 When I use the Kinect to get a point cloud with depthToPointCloud
it returns a 480 * 640 * 3
matrix. 当我使用Kinect获取具有depthToPointCloud
的点云时,它返回480 * 640 * 3
矩阵。
How can I extract the x, y, and z coordinates from this matrix so I can plot it with clickA3DPoint
? 如何从此矩阵中提取x,y和z坐标,以便我可以使用clickA3DPoint
绘制它? (or scatter3
?) (或scatter3
?)
My attempt so far: 我到目前为止的尝试:
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.
But this just plots the points along a diagonal line in the 3D space. 但这只是绘制了3D空间中对角线上的点。 How do I actually extract the x, y and z coordinates from a point cloud in Matlab? 如何从Matlab中的点云实际提取x,y和z坐标?
You can use the pcshow
function to plot your points, and it will take the M-by-N-by-3 array directly. 您可以使用pcshow
函数绘制您的点,它将直接采用M-by-N-by-3阵列。 You can then turn on data tips and click on the points in the plot to see their coordinates. 然后,您可以打开数据提示并单击绘图中的点以查看其坐标。
If you still want to create a 3-by-N matrix, then the easiest way to do that is the following: 如果您仍想创建3乘N矩阵,那么最简单的方法是:
x = xyzPoints(:,:,1);
y = xyzPoints(:,:,2);
z = zyzPoints(:,:,3);
points3D = [x(:)'; y(:)', z(:)'];
you can use the Property 'Location' of pointCloud to get the x,y,z. 您可以使用pointCloud的属性“位置”来获取x,y,z。 for example: 例如:
moving = movingReg.Location;%movingReg is a pointCloud
scatter(moving(:,1),moving(:,2));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.