MATLAB点云处理:查找感兴趣区域(ROI)内的点

Posted 借我十斤肉

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MATLAB点云处理:查找感兴趣区域(ROI)内的点相关的知识,希望对你有一定的参考价值。

1 函数语法与代码实现

语法:

两种重载

indices = findPointsInROI(ptCloud,roi)
indices = findpointsInROI(ptCloud,roi,camMatrix)

1.1 重载函数1:indices = findPointsInROI(ptCloud,roi)

描述:

返回输入点云中感兴趣区域(ROI)内的点。
使用基于Kd树的搜索算法获得指定ROI内的点。

示例1: 在点云中的长方体ROI中查找点

代码:

clc;
clear;
ptCloud = pcread('bunny.pcd');
roi = [-0.05 0 0.08 0.1 0 0.02];            % 在输入点云的x、y和z坐标范围内定义长方体ROI。
indices = findPointsInROI(ptCloud,roi);     % 找到位于长方体ROI内的点的索引。
ptCloudB = select(ptCloud,indices);         % 选择位于长方体ROI内的点并存储为点云对象。

% 显示输入点云和指定ROI内的点云。
figure
pcshow(ptCloud.Location,[0.5 0.5 0.5])      % 位置+颜色
hold on
pcshow(ptCloudB.Location,'r');              % 显示ROI内点云,附为红色
legend('Point Cloud','Points within ROI','Location','southoutside') % 添加图例
hold off

显示结果:

在这里插入图片描述

1.2 重载函数2:findpointsInROI(ptCloud,roi,camMatrix)

描述:

通过使用相机投影矩阵,在有组织的点云数据中找到长方体ROI内的点。从采样点云数据点及其对应的像点坐标计算摄像机投影矩阵。

将组织的点云数据加载到工作空间中。使用Kinect深度传感器生成点云。

示例2: 在有组织的点云中查找长方体ROI中的点

代码:

ld = load('object3d.mat');
ptCloud = ld.ptCloud;
stepSize = 100;				% 指定采样点云数据的步长

% 对输入点云进行采样,并将采样的三维点坐标存储为点云对象
indices = 1:stepSize:ptCloud.Count;
tempPtCloud = select(ptCloud,indices);

[tempPtCloud,validIndices] = removeInvalidPoints(tempPtCloud);		% 从采样点云中删除无效点
worldPoints = tempPtCloud.Location;									% 从输入点云中获取三维世界点坐标

% 找到输入点云的三维点坐标对应的二维图像坐标
[Y,X] = ind2sub([size(ptCloud.Location,1),size(ptCloud.Location,2)],indices);
imagePoints = [X(validIndices)' Y(validIndices)'];

camMatrix = estimateCameraMatrix(imagePoints,worldPoints);			% 根据图像和世界点坐标估计摄像机投影矩阵
roi = [0.3 0.7 0 0.4 0.1 0.3];										% 在输入点云的x、y和z坐标范围内指定长方体ROI
indices = findPointsInROI(ptCloud,roi,camMatrix);					% 找到位于长方体ROI内的点云数据的索引
ptCloudB = select(ptCloud,indices);									% 使用点云方法select获取ROI内点的点云数据

% 显示输入点云和长方体ROI内的点
figure
pcshow(ptCloud)
hold on
pcshow(ptCloudB.Location,'r');
legend('Point Cloud','Points within the ROI','Location','southoutside','Color',[1 1 1])
hold off

显示结果: (官网示例)

在这里插入图片描述

2 输入输出参数详解

2.1 输入参数

ptCloud — Point cloud

点云,指定为点云对象。

roi — Region of interest

感兴趣区域,指定为六元素向量形式 [ x m i n , x m a x , y m i n , y m a x , z m i n , z m a x ] [xmin,xmax,ymin,ymax,zmin,zmax] [xminxmaxyminymaxzminzmax],其中:
xmin和xmax分别是沿 x 轴的最小和最大限值。
ymin和ymax分别是沿 y 轴的最小和最大限值。
zmin和zmax分别是沿 z 轴的最小和最大极限。

camMatrix — Camera projection matrix

摄影机投影矩阵,指定为将三维世界点映射到二维图像点的4x3矩阵。您可以使用estimateCameraMatrix函数找到camMatrix。

2.2 输出参数

indices — Indices of stored points

存储点的索引,作为列向量返回。向量包含存储在点云中的ROI点的线性索引。


参考链接:

https://ww2.mathworks.cn/help/vision/ref/pointcloud.findpointsinroi.html#mw_5575f329-30ec-4fc3-9e32-1b4ff4d380fe

以上是关于MATLAB点云处理:查找感兴趣区域(ROI)内的点的主要内容,如果未能解决你的问题,请参考以下文章

图像处理中ROI是啥意思

OpenCV实战——图像感兴趣区域

基于opencv的感兴趣区域ROI的操作

图像处理中ROI是啥意思如题

OpenCV-C++选择提取感兴趣区域(ROI区域)附用鼠标选取ROI区域的代码

感兴趣区域ROI