首页 > PCL点云特征描述与提取(4)

PCL点云特征描述与提取(4)

#include #include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include typedef pcl::PointXYZ PointType;//参数的设置
float angular_resolution = 0.5f;
float support_size = 0.2f;
pcl::RangeImage::CoordinateFrame coordinate_frame = pcl::RangeImage::CAMERA_FRAME;
bool setUnseenToMaxRange = false;
bool rotation_invariant = true;//命令帮助
void 
printUsage (const char* progName)
{std::cout << "

Usage: "<" [options] 

"<< "Options:
"<< "-------------------------------------------
"<< "-r    angular resolution in degrees (default "<")
"<< "-c      coordinate frame (default "<< (int)coordinate_frame<<")
"<< "-m           Treat all unseen points to max range
"<< "-s    support size for the interest points (diameter of the used sphere - ""default "<")
"<< "-o <0/1>     switch rotational invariant version of the feature on/off"<<               " (default "<< (int)rotation_invariant<<")
"<< "-h           this help
"<< "

";
}void 
setViewerPose (pcl::visualization::PCLVisualizer& viewer, const Eigen::Affine3f& viewer_pose)//setViewerPose
{Eigen::Vector3f pos_vector = viewer_pose * Eigen::Vector3f (0, 0, 0);Eigen::Vector3f look_at_vector = viewer_pose.rotation () * Eigen::Vector3f (0, 0, 1) + pos_vector;Eigen::Vector3f up_vector = viewer_pose.rotation () * Eigen::Vector3f (0, -1, 0);viewer.setCameraPosition (pos_vector[0], pos_vector[1], pos_vector[2],look_at_vector[0], look_at_vector[1], look_at_vector[2],up_vector[0], up_vector[1], up_vector[2]);
}int 
main (int argc, char** argv)
{// 设置参数检测if (pcl::console::find_argument (argc, argv, "-h") >= 0){printUsage (argv[0]);return 0;}if (pcl::console::find_argument (argc, argv, "-m") >= 0){setUnseenToMaxRange = true;cout << "Setting unseen values in range image to maximum range readings.
";}if (pcl::console::parse (argc, argv, "-o", rotation_invariant) >= 0)cout << "Switching rotation invariant feature version "<< (rotation_invariant ? "on" : "off")<<".
";int tmp_coordinate_frame;if (pcl::console::parse (argc, argv, "-c", tmp_coordinate_frame) >= 0){coordinate_frame = pcl::RangeImage::CoordinateFrame (tmp_coordinate_frame);cout << "Using coordinate frame "<< (int)coordinate_frame<<".
";}if (pcl::console::parse (argc, argv, "-s", support_size) >= 0)cout << "Setting support size to "<".
";if (pcl::console::parse (argc, argv, "-r", angular_resolution) >= 0)cout << "Setting angular resolution to "<"deg.
";angular_resolution = pcl::deg2rad (angular_resolution);//打开一个磁盘中的.pcd文件  但是如果没有指定就会自动生成pcl::PointCloud::Ptr    point_cloud_ptr (new pcl::PointCloud);pcl::PointCloud& point_cloud = *point_cloud_ptr;pcl::PointCloud far_ranges;Eigen::Affine3f scene_sensor_pose (Eigen::Affine3f::Identity ());std::vector<int> pcd_filename_indices = pcl::console::parse_file_extension_argument (argc, argv, "pcd");if (!pcd_filename_indices.empty ())   //检测是否有far_ranges.pcd
  {std::string filename = argv[pcd_filename_indices[0]];if (pcl::io::loadPCDFile (filename, point_cloud) == -1){cerr << "Was not able to open file ""<"".
";printUsage (argv[0]);return 0;}scene_sensor_pose = Eigen::Affine3f (Eigen::Translation3f (point_cloud.sensor_origin_[0],point_cloud.sensor_origin_[1],point_cloud.sensor_origin_[2])) *Eigen::Affine3f (point_cloud.sensor_orientation_);std::string far_ranges_filename = pcl::getFilenameWithoutExtension (filename)+"_far_ranges.pcd";if (pcl::io::loadPCDFile (far_ranges_filename.c_str (), far_ranges) == -1)std::cout << "Far ranges file ""<"" does not exists.
";}else{setUnseenToMaxRange = true;cout << "
No *.pcd file given => Genarating example point cloud.

";for (float x=-0.5f; x<=0.5f; x+=0.01f)   //如果没有打开的文件就生成一个矩形的点云
    {for (float y=-0.5f; y<=0.5f; y+=0.01f){PointType point;  point.x = x;  point.y = y;  point.z = 2.0f - y;point_cloud.points.push_back (point);}}point_cloud.width = (int) point_cloud.points.size ();  point_cloud.height = 1;}//从点云中建立生成深度图float noise_level = 0.0;    float min_range = 0.0f;int border_size = 1;boost::shared_ptr range_image_ptr (new pcl::RangeImage);pcl::RangeImage& range_image = *range_image_ptr;   range_image.createFromPointCloud (point_cloud, angular_resolution, pcl::deg2rad (360.0f), pcl::deg2rad (180.0f),scene_sensor_pose, coordinate_frame, noise_level, min_range, border_size);range_image.integrateFarRanges (far_ranges);if (setUnseenToMaxRange)range_image.setUnseenToMaxRange ();//打开3D viewer并加入点云pcl::visualization::PCLVisualizer viewer ("3D Viewer");viewer.setBackgroundColor (1, 1, 1);pcl::visualization::PointCloudColorHandlerCustom range_image_color_handler (range_image_ptr, 0, 0, 0);viewer.addPointCloud (range_image_ptr, range_image_color_handler, "range image");viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "range image");//viewer.addCoordinateSystem (1.0f, "global");//PointCloudColorHandlerCustom point_cloud_color_handler (point_cloud_ptr, 150, 150, 150);//viewer.addPointCloud (point_cloud_ptr, point_cloud_color_handler, "original point cloud");
  viewer.initCameraParameters ();setViewerPose (viewer, range_image.getTransformationToWorldSystem ());//显示pcl::visualization::RangeImageVisualizer range_image_widget ("Range image");range_image_widget.showRangeImage (range_image);//提取NARF特征pcl::RangeImageBorderExtractor range_image_border_extractor;    //申明深度图边缘提取器pcl::NarfKeypoint narf_keypoint_detector;                       //narf_keypoint_detector为点云对象
narf_keypoint_detector.setRangeImageBorderExtractor (&range_image_border_extractor);narf_keypoint_detector.setRangeImage (&range_image);narf_keypoint_detector.getParameters ().support_size = support_size;    //获得特征提取的大小
  pcl::PointCloud<int> keypoint_indices;narf_keypoint_detector.compute (keypoint_indices);std::cout << "Found "<" key points.
";// ----------------------------------------------// -----Show keypoints in range image widget-----// ----------------------------------------------//for (size_t i=0; i//range_image_widget.markPoint (keypoint_indices.points[i]%range_image.width,//keypoint_indices.points[i]/range_image.width);//在3Dviewer显示提取的特征信息pcl::PointCloud::Ptr keypoints_ptr (new pcl::PointCloud);pcl::PointCloud& keypoints = *keypoints_ptr;keypoints.points.resize (keypoint_indices.points.size ());for (size_t i=0; ii)keypoints.points[i].getVector3fMap () = range_image.points[keypoint_indices.points[i]].getVector3fMap ();pcl::visualization::PointCloudColorHandlerCustom keypoints_color_handler (keypoints_ptr, 0, 255, 0);viewer.addPointCloud (keypoints_ptr, keypoints_color_handler, "keypoints");viewer.setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 7, "keypoints");//在关键点提取NARF描述子std::vector<int> keypoint_indices2;keypoint_indices2.resize (keypoint_indices.points.size ());for (unsigned int i=0; i// This step is necessary to get the right vector typekeypoint_indices2[i]=keypoint_indices.points[i];      ///建立NARF关键点的索引向量,此矢量作为NARF特征计算的输入来使用
pcl::NarfDescriptor narf_descriptor (&range_image, &keypoint_indices2);//创建narf_descriptor对象。并给了此对象输入数据(特征点索引和深度像)narf_descriptor.getParameters ().support_size = support_size;//support_size确定计算描述子时考虑的区域大小narf_descriptor.getParameters ().rotation_invariant = rotation_invariant;    //设置旋转不变的NARF描述子pcl::PointCloud narf_descriptors;               //创建Narf36的点类型输入点云对象并进行实际计算narf_descriptor.compute (narf_descriptors);                 //计算描述子cout << "Extracted "<" descriptors for "   //打印输出特征点的数目和提取描述子的数目<" keypoints.
";//主循环函数while (!viewer.wasStopped ()){range_image_widget.spinOnce ();  // process GUI events
    viewer.spinOnce ();pcl_sleep(0.01);}
}

更多相关:

  • 招募一起学习的小伙伴,加入我们群聊中,定期分享论文,以及工程相关的问题,讨论分享。根据自己的爱好,加入不同的点云交流群,我们期待有学习点云深度学习,点云PCL,cloudcompare,以及GDAL,Open3D相关的研究人员加入我们。加入方式:后台发送微信群,按要求备注即可。       pcl_filters库包含3D点云数据的...

  • 此为文章初稿还没有完善,应该还有一些问题,等待后面有时间再继续更新,原创文章,未经允许,请勿转载!!! 首先介绍在PCL库中经常使用的两种点云之间的转换,这里将根据工程中的经验,从代码层面举例分析如何实现程序中定义的各种点云数据之间转换,并且介绍PCL在应用于ROS中应该如何转换数据结构。 (1)pcl::PCLPointClou...

  • 在PCL 的点云库中大量的使用动态内存的方式编程,比如: pcl::PCLPointCloud2::Ptr cloud (new pcl::PCLPointCloud2 ()); PointCloudT::Ptr cloud = boost::shared_ptr (new PointCloudT ())...

  • PCL(Point Cloud Library)是在吸收了前人点云相关研究基础上建立起来的大型跨平台开源C++编程库,它实现了大量点云相关的通用算法和高效数据结构,涉及到点云获取、滤波、分割、配准、检索、特征提取、识别、追踪、曲面重建、可视化等。支持多种操作系统平台,可在Windows、Linux、Android、Mac OS X、部...

  • 关于输入一个具体的物体的点云,从场景中找出与该物体点云相匹配的,这种方法可以用来抓取指定的物体等等,具体的代码的解释如下,需要用到的一些基础的知识,在之前的博客中都有提及,其中用到的一些方法可以翻阅前面的博客,当然有问题可以关注公众号,与众多爱好者一起交流   具体的代码实现 #include ...

  •  IIF函数判断 Sub 判断4()  Range("a3") = IIf(Range("a1") <= 0, "负数或零", "负数")End Sub Sub 判断1() '单条件判断  If Range("a1").Value > 0 Then     Range("b1") = "正数"  Else     Range("b1"...

  • #include                        #include #include #include    ...

  • # 调整图像亮度input_image = cv2.cvtColor(input_image , cv2.COLOR_BGR2HSV)input_image [:, :, 2] = scale_value * input_image [:, :, 2]input_image [:, :, 2][input_image [:, :, 2...

  • area_center_gray ( Regions, Image : : : Area, Row, Column )    计算Image图像中Region区域的面积Area和重心(Row,Column)。 cooc_feature_image ( Regions, Image : : LdGray, Direction : En...

  • 1、显示一幅二值图像: >> bw = zeros(90,90); >> bw(2:2:88,2:2:88) = 1; >> imshow(bw); >> 2、利用image函数显示一幅索引图像:   >> [X,MAP] = imread('E:STUDY_softwareMatlab2016images11.jp...

  • iOS 相册和网络图片的存取 保存 UIImage 到相册 UIKit UIKit 中一个古老的方法,Objective-C 的形式 void UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void...