网上看了很多教程,没看到圆柱提取后的系数解释。

源码如下:

#include <pcl/ModelCoefficients.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/filters/passthrough.h>
#include <pcl/features/normal_3d.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/sample_consensus/model_types.h>
#include <pcl/segmentation/sac_segmentation.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <boost/thread/thread.hpp> #include <pcl/filters/radius_outlier_removal.h> typedef pcl::PointXYZ PointT; // All the objects needed
pcl::PCDReader reader;
pcl::PassThrough<PointT> pass;
pcl::NormalEstimation<PointT, pcl::Normal> ne;
pcl::SACSegmentationFromNormals<PointT, pcl::Normal> seg;
pcl::PCDWriter writer;
pcl::ExtractIndices<PointT> extract; pcl::search::KdTree<PointT>::Ptr tree(new pcl::search::KdTree<PointT>()); // Datasets
pcl::PointCloud<PointT>::Ptr cloud(new pcl::PointCloud<PointT>); pcl::PointCloud<pcl::Normal>::Ptr cloud_normals(new pcl::PointCloud<pcl::Normal>); pcl::ModelCoefficients::Ptr coefficients_plane(new pcl::ModelCoefficients), coefficients_cylinder(new pcl::ModelCoefficients);
pcl::PointIndices::Ptr inliers_plane(new pcl::PointIndices), inliers_cylinder(new pcl::PointIndices); boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("viewer"));
pcl::PointCloud<pcl::PointXYZ>::Ptr clicked_points_3d(new pcl::PointCloud<pcl::PointXYZ>);
int num = ; void pp_callback(const pcl::visualization::AreaPickingEvent& event, void* args)
{ clicked_points_3d->points.clear();
pcl::PointCloud<pcl::PointXYZ>::Ptr final(new pcl::PointCloud<pcl::PointXYZ>);
std::vector< int > indices;
if (event.getPointsIndices(indices) == -)
return; for (int i = ; i < indices.size(); ++i)
{
clicked_points_3d->points.push_back(cloud->points.at(indices[i]));
}
//clicked_points_3d->width = 1;
//clicked_points_3d->height = clicked_points_3d->size();
//if (!clicked_points_3d->points.empty())
//{
// writer.write("Selected.pcd", *clicked_points_3d, false);
//} // Estimate point normals
ne.setSearchMethod(tree);
ne.setInputCloud(clicked_points_3d);
ne.setKSearch();
ne.compute(*cloud_normals); // Create the segmentation object for cylinder segmentation and set all the parameters
seg.setOptimizeCoefficients(true);
seg.setModelType(pcl::SACMODEL_CYLINDER);
seg.setMethodType(pcl::SAC_RANSAC);
seg.setNormalDistanceWeight(0.1);
seg.setMaxIterations();
double threshold;
std::cout << "threshold: ";
std::cin >> threshold;
seg.setDistanceThreshold(threshold); //单位米
double radius;
std::cout << "radius: ";
std::cin >> radius;
seg.setRadiusLimits(, radius); //单位米
seg.setInputCloud(clicked_points_3d);
seg.setInputNormals(cloud_normals); // Obtain the cylinder inliers and coefficients
seg.segment(*inliers_cylinder, *coefficients_cylinder);
std::cerr << "Cylinder coefficients: " << *coefficients_cylinder << std::endl; // Write the cylinder inliers to disk
extract.setInputCloud(clicked_points_3d);
extract.setIndices(inliers_cylinder);
extract.setNegative(false);
pcl::PointCloud<PointT>::Ptr cloud_cylinder(new pcl::PointCloud<PointT>());
extract.filter(*cloud_cylinder);
if (cloud_cylinder->points.empty())
std::cerr << "Can't find the cylindrical component." << std::endl;
else
{
std::cerr << "PointCloud representing the cylindrical component: " << cloud_cylinder->points.size() << " data points." << std::endl;
cloud_cylinder->width = ;
cloud_cylinder->height = cloud_cylinder->size();
writer.write("table_scene_mug_stereo_textured_cylinder.pcd", *cloud_cylinder, false);
}
system("pause"); std::stringstream ss;
std::string cloudName;
ss << num++;
ss >> cloudName;
cloudName += "_cloudName"; pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> red(clicked_points_3d, , , );
viewer->addPointCloud(clicked_points_3d, red, cloudName);
viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, , cloudName); //std::stringstream ss;
//std::string cloudName;
ss << num++;
ss >> cloudName;
cloudName += "_cloudName";
pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> blue(cloud_cylinder, , , );
viewer->addPointCloud(cloud_cylinder, blue, cloudName);
viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, , cloudName);
} int main (int argc, char** argv)
{
//std::string location;
//std::getline(std::cin, location);
//if (location[0] == '"')
//{
// location = location.substr(1, location.length() - 2);
//}
//if (pcl::io::loadPCDFile<pcl::PointXYZ>(location, *cloud) == -1)
//{
// PCL_ERROR("Couldn't read file \n");
// system("pause");
//}
//std::cout << "Reading Success" << std::endl; //生成圆柱点云
for (float z(-); z <= ; z += 0.5)
{
for (float angle(0.0); angle <= 360.0; angle += 5.0)
{
pcl::PointXYZ basic_point;
basic_point.x = +3.5*cos(angle / * M_PI);
basic_point.y = +3.5*sin(angle / * M_PI);
basic_point.z = z;
cloud->points.push_back(basic_point);
}
} //// Read in the cloud data
//reader.read ("table_scene_mug_stereo_textured.pcd", *cloud);
//std::cerr << "PointCloud has: " << cloud->points.size () << " data points." << std::endl; // Build a passthrough filter to remove spurious NaNs
//pass.setInputCloud (cloud);
//pass.setFilterFieldName ("z");
//pass.setFilterLimits (0, 1.5);
//pass.filter (*#);
//std::cerr << "PointCloud after filtering has: " << cloud_filtered->points.size () << " data points." << std::endl;
viewer->addPointCloud(cloud, "bunny");
viewer->setCameraPosition(, , -, , -, , );
viewer->registerAreaPickingCallback(pp_callback, (void*)&cloud); while (!viewer->wasStopped())
{
viewer->spinOnce();
boost::this_thread::sleep(boost::posix_time::microseconds());
} return ();
}

程序运行后看不见点云按R键

接着按下X键选中点云,再按下X键

设置偏差阈值为1

圆柱的半径大于3.5

就可以得到如下结果

系数0、1、2代表圆柱轴线上的原点,3、4、5代表这条轴线的方向向量,系数6就是圆柱的半径。

PCL提取圆柱系数的更多相关文章

  1. 基于DCT系数的实时监控中运动目标检测

    本文的主要内容来自2009 Advanced Video and Signal Based Surveillance会议的一篇论文“Real-Time Moving Object Detection ...

  2. MSCN(Mean Subtracted Contrast Normalized)系数的直方图

    MSCN系数是无参考的空间域图像质量评估算法BRISQUE(No-Reference Image Quality Assessment in the Spatial Domain)中提出的,MSCN系 ...

  3. 基于GPU的高分一号影像正射校正的设计与实现

    一 RPC正射校正的原理 影像正射校正的方法有很多,主要包含两大类:一类是严格的几何纠正模型,另一类是近似几何纠正模型.当遥感影像的成像模型和有关参数已知时,可以根据严格的成像模型来校正图像,这种方法 ...

  4. 基于FPGA的音频信号的FIR滤波(Matlab+Modelsim验证)

    1 设计内容 本设计是基于FPGA的音频信号FIR低通滤波,根据要求,采用Matlab对WAV音频文件进行读取和添加噪声信号.FFT分析.FIR滤波处理,并分析滤波的效果.通过Matlab的分析验证滤 ...

  5. 基于HTK语音工具包进行孤立词识别的使用教程

    选自:http://my.oschina.net/jamesju/blog/116151 1前言 最近一直在研究HTK语音识别工具包,前几天完成了工具包的安装编译和测试,这几天又按耐不住好奇,决定自己 ...

  6. ECG信号读出,检测QRS,P,T 波(小波去噪,并根据检测),基于BP辨识的神经网络

    这学期的课程选择神经网络.最后的作业处理ECG信号,并利用神经网络识别. 1  ECG引进和阅读ECG信号 1)ECG介绍  详细ECG背景应用就不介绍了,大家能够參考百度 谷歌.仅仅是简单说下ECG ...

  7. OO第一单元总结

    OO第一单元作业总结 一.前言 开学四周,不知不觉已经做了三次OO作业.事实上,每一次作业对我来说都是很大的挑战,需要花费大量的时间和精力来学习. 虽然学得很艰苦,但最后还是连滚带爬地完成了.(好惨一 ...

  8. Nature重磅:Hinton、LeCun、Bengio三巨头权威科普深度学习

    http://wallstreetcn.com/node/248376 借助深度学习,多处理层组成的计算模型可通过多层抽象来学习数据表征( representations).这些方法显著推动了语音识别 ...

  9. [译]用R语言做挖掘数据《七》

    时间序列与数据挖掘 一.实验说明 1. 环境登录 无需密码自动登录,系统用户名shiyanlou,密码shiyanlou 2. 环境介绍 本实验环境采用带桌面的Ubuntu Linux环境,实验中会用 ...

随机推荐

  1. 退出状态、测试(test or [])、操作符、[]与[[]]区别

    一.退出状态 系统每执行一个命令,都会返回一个退出状态,若返回退出状态为0,表示命令执行成功, 若返回退出状态不为0,表示命令执行有错误. echo  $? 可以打印出退出状态. 例如:ls echo ...

  2. Authenticator App 两步验证会不会造成亚马逊账号关联?

    今天听人说,因为用Authenticator App做亚马逊两步验证造成了帐号关联…… 我给大家解释一下Authenticator的实现原理,作为计算机专业科班出身的我,此次从各方面了解并经过自己亲测 ...

  3. bat脚本的基本命令语法

    bat脚本的基本命令语法 一.批处理的常见命令 1.REM 和 ::     2.ECHO 和 @     3.PAUSE     4.ERRORLEVEL     5.TITLE     6.COL ...

  4. docker本地化异常:/bin/sh: warning: setlocale: LC_ALL: cannot change locale (en_US.UTF-8)

    docker中经常设置不了 环境变量$LC_ALL,  导致报很多奇怪的编码错误: /bin/sh: warning: setlocale: LC_ALL: cannot change locale ...

  5. Python实现PIL将图片转成字符串

    # -*- coding: utf-8 -*- # author:baoshan from PIL import Image, ImageFilter codeLib = '''@#$%&?* ...

  6. 使用GridSearchCV进行网格搜索微调模型

    import numpy as np import pandas as pd from sklearn.feature_extraction.text import TfidfVectorizer f ...

  7. tushare包使用案例

    Tushare是一个免费.开源的python财经数据接口包.主要实现对股票等金融数据从数据采集.清洗加工 到 数据存储的过程,能够为金融分析人员提供快速.整洁.和多样的便于分析的数据,为他们在数据获取 ...

  8. centos7.3部署memcached服务

    我们需要下载libevent和memcached这两个压缩包进行安装,可使用以下百度网盘链接进行下载 链接:https://pan.baidu.com/s/1vehZ5odzXFKwNjWT9_W0T ...

  9. [LeetCode] 71. Simplify Path 简化路径

    Given an absolute path for a file (Unix-style), simplify it. For example,path = "/home/", ...

  10. [LeetCode] 225. Implement Stack using Queues 用队列来实现栈

    Implement the following operations of a stack using queues. push(x) -- Push element x onto stack. po ...