当前位置: 首页 > 工具软件 > Sift Cloud > 使用案例 >

PCL:SIFT特征点估计

蒋默
2023-12-01

介绍:SIFT
下面是将RGB视为强度进行计算,也可以选择其他的字段进行处理。
主要就是理解参数,代码如下:

// 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/keypoints/impl/sift_keypoint.hpp>
#include <pcl/features/normal_3d.h>
// #include <pcl/visualization/pcl_visualizer.h>
	
int
main(int, char** argv)
{
  std::string filename = argv[1];
  std::cout << "Reading " << filename << std::endl;
  pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
  if(pcl::io::loadPCDFile<pcl::PointXYZRGB> (filename, *cloud) == -1) // load the file
  {
  PCL_ERROR ("Couldn't read file");
  return -1;
  }
  std::cout << "points: " << cloud->points.size () <<std::endl;
  
  // Parameters for sift computation
  const float min_scale = 0.1f;
  const int n_octaves = 6;
  const int n_scales_per_octave = 10;
  const float min_contrast = 0.5f;
  
  
  // Estimate the sift interest points using Intensity values from RGB values
  pcl::SIFTKeypoint<pcl::PointXYZRGB, pcl::PointWithScale> sift;
  pcl::PointCloud<pcl::PointWithScale> result;
  pcl::search::KdTree<pcl::PointXYZRGB>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZRGB> ());
  sift.setSearchMethod(tree);
  sift.setScales(min_scale, n_octaves, n_scales_per_octave);
  sift.setMinimumContrast(min_contrast);
  sift.setInputCloud(cloud);
  sift.compute(result);
  
  // Copying the pointwithscale to pointxyz so as visualize the cloud
  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_temp (new pcl::PointCloud<pcl::PointXYZ>);
  copyPointCloud(result, *cloud_temp);

  // Saving the resultant cloud 
  std::cout << "Resulting sift points are of size: " << cloud_temp->points.size () <<std::endl;
  pcl::io::savePCDFileASCII("sift_points.pcd", *cloud_temp);
  return 0;
  
}

来源:PCL官方示例

 类似资料: