4
  • 我有一个 3-D 几何形状,我必须将其转换为点云。
  • 由此产生的点云可以被认为等同于从对象的激光扫描输出的点云。
  • 不需要网格生成
  • 生成的点可能是均匀分布的,也可能只是随机分布的——没关系
  • 可以以 3-D 数学公式的形式提供 3-D 形状
  • 这必须使用 MATLAB 完成
4

2 回答 2

4

没有示例很难回答,但听起来您只想进行蒙特卡罗模拟

假设您的形状由函数定义,f并且您将 X、Y 限制存储在两个元素向量中,例如 xlim = [-10 10] 即此形状的所有可能 x 值位于 x = -10 和 x = 10 之间,然后我如果特定 xy 对没有值,建议您f返回某种错误代码。我会假设那将是NaNf(x,y)您正在编写的函数也是如此,如果z可以或NaN不能返回 a

n= 10000;
counter  = 1;
shape = nan(n, 3)
while counter < n
   x = rand*diff(xlim) + mean(xlmin);
   y = rand*diff(ylim) + mean(ylim);
   z = f(x,y)
   if ~isnan(z)
      shape(counter, :) = [x, y, z];
      counter = counter + 1    
   end
end

因此,上面的代码将在您的形状上随机采样 10000 个(非唯一的,但很容易适应)点。

现在输入这个之后,我意识到也许你的形状实际上并没有那么大,也许你可以统一采样而不是随机采样:

for x = xlim(1):xstep:xlim(2)
   for y = ylim(1):ystep:ylim(2)
       shape(counter, :) = [x, y, f(x,y)];
   end
end 

或者如果你写f的是矢量化(最好)

shape = [(xlim(1):xstep:xlim(2))', (ylim(1):ystep:ylim(2))', f(xlim(1):xstep:xlim(2), ylim(1):ystep:ylim(2));

然后无论哪种方式

shape(isnan(shape(:, 3), :) = []; %remove the points that fell outside the shape
于 2013-04-19T06:32:52.947 回答
1

这是使用 PrimeSense 相机的深度图像创建云图像的代码。

此功能的输入/输出:

-inputs
 depth         -depth map
 topleft       -topleft coordinates of the segmented image in the whole image

-outputs
 pclouds       -3d point clouds

MatLab 代码:

depth = double(depth);
% Size of camera image
center = [320 240];
[imh, imw] = size(depth);
constant = 570.3;

% convert depth image to 3d point clouds
pclouds = zeros(imh,imw,3);
xgrid = ones(imh,1)*(1:imw) + (topleft(1)-1) - center(1);
ygrid = (1:imh)'*ones(1,imw) + (topleft(2)-1) - center(2);
pclouds(:,:,1) = xgrid.*depth/constant;
pclouds(:,:,2) = ygrid.*depth/constant;
pclouds(:,:,3) = depth;
distance = sqrt(sum(pclouds.^2,3));

编辑:此来源来自当前的文章http://www.cs.washington.edu/rgbd-dataset/software.html

您可以在 MatLab 和 C++ 中找到您可能感兴趣的其他一些 Cloud 函数。

于 2013-04-19T12:52:36.253 回答