PCL:SIFT特征点估计(法线)
作者:互联网
介绍:SIFT
将法线视为强度进行计算,代码如下:
需要四个字段的点云才能计算。
// STL
#include <iostream>
// PCL
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/common/io.h>
#include <pcl/keypoints/sift_keypoint.h>
#include <pcl/features/normal_3d.h>
// #include <pcl/visualization/pcl_visualizer.h>
/* This example shows how to estimate the SIFT points based on the
* Normal gradients i.e. curvature than using the Intensity gradient
* as usually used for SIFT keypoint estimation.
*/
int
main(int, char** argv)
{
std::string filename = argv[1];
std::cout << "Reading " << filename << std::endl;
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_xyz (new pcl::PointCloud<pcl::PointXYZ>);
if(pcl::io::loadPCDFile<pcl::PointXYZ> (filename, *cloud_xyz) == -1) // load the file
{
PCL_ERROR ("Couldn't read file");
return -1;
}
std::cout << "points: " << cloud_xyz->points.size () <<std::endl;
// Parameters for sift computation
const float min_scale = 0.01f;
const int n_octaves = 3;
const int n_scales_per_octave = 4;
const float min_contrast = 0.001f;
// Estimate the normals of the cloud_xyz
pcl::NormalEstimation<pcl::PointXYZ, pcl::PointNormal> ne;
pcl::PointCloud<pcl::PointNormal>::Ptr cloud_normals (new pcl::PointCloud<pcl::PointNormal>);
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree_n(new pcl::search::KdTree<pcl::PointXYZ>());
ne.setInputCloud(cloud_xyz);
ne.setSearchMethod(tree_n);
ne.setRadiusSearch(0.2);
ne.compute(*cloud_normals);
// Copy the xyz info from cloud_xyz and add it to cloud_normals as the xyz field in PointNormals estimation is zero
for(size_t i = 0; i<cloud_normals->points.size(); ++i)
{
cloud_normals->points[i].x = cloud_xyz->points[i].x;
cloud_normals->points[i].y = cloud_xyz->points[i].y;
cloud_normals->points[i].z = cloud_xyz->points[i].z;
}
// Estimate the sift interest points using normals values from xyz as the Intensity variants
pcl::SIFTKeypoint<pcl::PointNormal, pcl::PointWithScale> sift;
pcl::PointCloud<pcl::PointWithScale> result;
pcl::search::KdTree<pcl::PointNormal>::Ptr tree(new pcl::search::KdTree<pcl::PointNormal> ());
sift.setSearchMethod(tree);
sift.setScales(min_scale, n_octaves, n_scales_per_octave);
sift.setMinimumContrast(min_contrast);
sift.setInputCloud(cloud_normals);
sift.compute(result);
std::cout << "No of SIFT points in the result are " << result.points.size () << std::endl;
return 0;
}
也可以自定义SIFT选择的字段,下面代码说明选择Z字段作为强度信息进行处理:
// STL
#include <iostream>
// PCL
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/common/io.h>
#include <pcl/keypoints/sift_keypoint.h>
#include <pcl/features/normal_3d.h>
// #include <pcl/visualization/pcl_visualizer.h>
/* This examples shows how to estimate the SIFT points based on the
* z gradient of the 3D points than using the Intensity gradient as
* usually used for SIFT keypoint estimation.
*/
namespace pcl
{
template<>
struct SIFTKeypointFieldSelector<PointXYZ>
{
inline float
operator () (const PointXYZ &p) const
{
return p.z;
}
};
}
int
main(int, char** argv)
{
std::string filename = argv[1];
std::cout << "Reading " << filename << std::endl;
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_xyz (new pcl::PointCloud<pcl::PointXYZ>);
if(pcl::io::loadPCDFile<pcl::PointXYZ> (filename, *cloud_xyz) == -1) // load the file
{
PCL_ERROR ("Couldn't read file");
return -1;
}
std::cout << "points: " << cloud_xyz->points.size () <<std::endl;
// Parameters for sift computation
const float min_scale = 0.005f;
const int n_octaves = 6;
const int n_scales_per_octave = 4;
const float min_contrast = 0.005f;
// Estimate the sift interest points using z values from xyz as the Intensity variants
pcl::SIFTKeypoint<pcl::PointXYZ, pcl::PointWithScale> sift;
pcl::PointCloud<pcl::PointWithScale> result;
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ> ());
sift.setSearchMethod(tree);
sift.setScales(min_scale, n_octaves, n_scales_per_octave);
sift.setMinimumContrast(min_contrast);
sift.setInputCloud(cloud_xyz);
sift.compute(result);
std::cout << "No of SIFT points in the result are " << result.points.size () << std::endl;
return 0;
}
来源:PCL官方示例
标签:PCL,xyz,sift,SIFT,点估计,pcl,include,cloud,points 来源: https://blog.csdn.net/com1098247427/article/details/120688904