本节将演示如何检测点云的3DHarris角点。
Harris算子是常见的特征检测算子,既可以提取角点也可以提取边缘点。与2DHarris角点检测原理不同,3DHarris角点检测利用的是点云法向量的信息。
首先介绍一下Harris算子所用到的类:
pcl::HarrisKeypoint2D< PointInT, PointOutT, IntensityT > | HarrisKeypoint2D (ResponseMethod method= HARRIS, int window_width =3 , int window_height=3, int min_distance=S, float threshold= 0. 0) |
重构函数。method 设置需要采用那种关键点检测方法,有 HARRIS, NOBLE,LOWE, TOMASI 四种方法,默认为 H ARRIS;window_width 、 window_height 为检测窗口的宽度和高度, min_distance 为两个关键点之间允许的最小距离, threshold为判断是否为关键点的感兴趣程度的阁值,小于该阔值的点被忽略,大于的则认为是关键点 。 | |
void | setMethod (ResponseMethod type) |
设置检测方法 | |
void | setWindowWidth (int window width) setWindowHeight (int window_height) |
设置检测窗口宽度、高度 | |
void | setSkippedPixels (int skipped_pixels) |
设置在检测时每次跳过的像素数目 | |
void | setMinimalDistance (int min_distance) |
设置候选关键点之间的最小距离 | |
void | setThreshold ( float threshold) |
设置感兴趣阈值 | |
void | setNonMaxSupression ( bool= false) |
设置是否对小于感兴趣阈值的点进行剔除,如果为 true 则进行剔除,对结果进行优化,如果为 false 则返回每个点,无论其感兴趣值大于或小于感兴趣阈值。 | |
void | setRefine (booldo refine) |
设置是否对所得关键点结果进行重新计算优化 | |
void | setNumberOfThreads (intnr threads) |
设置该算法如果采用 OpenMP 并行机制,能够创建的线程数目 | |
void | compute (PointCloudOut &output) |
计算获取关键点,存储在 output 中 。 |
pcl::HarrisKeypoint3D< PointInT, PointOutT, NormalT > | HarrisKeypoint3D ( ResponseMethod method = HARRIS, float radius =0. 0lf, float threshold = 0. 0f) |
重构函数, method 设置需要采用哪种关键点检测方法,有 HARRIS, NOBLE,LOWE, TOMASI, CURVATURE 五种方法,默认为 HARRIS, radius 为法线估计的搜索半径,同时也是计算兴趣值的支持区域, threshold 为判断是否为关键点的感兴趣程度的阈值,小于该阈值的点被忽略,大于的则认为是关键点 | |
类 HarrisKeypoint6D | |
类 HarrisKeypoint6D 与 HarrisK eypoint2D 类似, 只是利用了欧氏空间域 XYZ或者强度域来确定候选关键点,或者前两者的交集,即同时满足 XYZ 域和强度域的关键点为候选关键点。 | |
pcl::HarrisKeypoint6D< PointInT, PointOutT, NormalT > | HarrisKeypoint6D (float radius =O. 01, float threshold = 0. 0) |
重构函数,注意此处并没有方法选择的参数,通过源代码可以看出其只采用 Tomasi 提出的方法实现关键点检测, radius 为法线估计的搜索半径,同时也是计算兴趣值的支持区域, threshold 为判断是否为关键点的感兴趣程度的阈值,小于该阈值的点被忽略,大于的则认为是关键点。 |
#pragma warning(disable:4996)
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL);
VTK_MODULE_INIT(vtkInteractionStyle);
#include <iostream>
#include <pcl\io\pcd_io.h>
#include <pcl/point_cloud.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/io/io.h>
#include <pcl/keypoints/harris_3D.h>//harris特征点估计类头文件声明
#include <cstdlib>
#include <vector>
#include <pcl/console/parse.h>
using namespace std;
int main(int argc, char *argv[])
{
pcl::PointCloud<pcl::PointXYZ>::Ptr input_cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::io::loadPCDFile("F:\\C++project\\roorm.pcd", *input_cloud);
pcl::PCDWriter writer;
float r_normal;
float r_keypoint;
r_normal = 0.1;
r_keypoint = 0.1;
typedef pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZI> ColorHandlerT3;
pcl::PointCloud<pcl::PointXYZI>::Ptr Harris_keypoints(new pcl::PointCloud<pcl::PointXYZI>());
pcl::HarrisKeypoint3D<pcl::PointXYZ, pcl::PointXYZI, pcl::Normal>* harris_detector = new pcl::HarrisKeypoint3D<pcl::PointXYZ, pcl::PointXYZI, pcl::Normal>;
//harris_detector->setNonMaxSupression(true);
harris_detector->setRadius(r_normal); //设置法向量估算的半径
harris_detector->setRadiusSearch(r_keypoint); //设置关键点估计的近邻搜索半径
harris_detector->setInputCloud(input_cloud);
//harris_detector->setNormals(normal_source);
//harris_detector->setMethod(pcl::HarrisKeypoint3D<pcl::PointXYZRGB,pcl::PointXYZI>::LOWE);
harris_detector->compute(*Harris_keypoints);
cout << "Harris_keypoints的大小是" << Harris_keypoints->size() << endl;
writer.write<pcl::PointXYZI>("Harris_keypoints.pcd", *Harris_keypoints, false);
pcl::visualization::PCLVisualizer visu3("clouds");
visu3.setBackgroundColor(255, 255, 255);
visu3.addPointCloud(Harris_keypoints, ColorHandlerT3(Harris_keypoints, 0.0, 0.0, 255.0), "Harris_keypoints");
visu3.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 8, "Harris_keypoints");
visu3.addPointCloud(input_cloud, "input_cloud");
visu3.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 0, 0, 0, "input_cloud");
visu3.spin();
}