不知道什么时间收集的code
///直通滤波
//#include "pch.h"
//#include <pcl/point_cloud.h>
//#include <pcl/point_types.h>
//#include <pcl/filters/passthrough.h>//直通滤波
//#include <pcl/io/pcd_io.h> //文件输入输出
//
//using namespace std;
//
///** \brief 直通滤波
// * \param[in] cloud_in 输入点云
// * \param[in] z_small Z方向小值
// * \param[in] z_big z方向大值
// * \param[in] x_small X方向小值
// * \param[in] x_big X方向大值
// * \param[in] y_small Y方向小值
// * \param[in] y_big Y方向大值
// * \param[out] cloud_out 输出点云
// */
//void passFilter(pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud_in,
// float z_small, float z_big, float x_small, float x_big, float y_small, float y_big,
// pcl::PointCloud<pcl::PointXYZ>::Ptr & cloud_out)
//{
// pcl::PointCloud < pcl::PointXYZ >::Ptr cloud(new pcl::PointCloud < pcl::PointXYZ >);
// pcl::PassThrough<pcl::PointXYZ> pass; // 设置滤波器对象
// pass.setInputCloud(cloud_in);
// pass.setFilterFieldName("z");
// pass.setFilterLimits(z_small, z_big);
// pass.filter(*cloud);
// pass.setInputCloud(cloud);
// pass.setFilterFieldName("x");
// pass.setFilterLimits(x_small, x_big);
// pass.filter(*cloud);
// pass.setInputCloud(cloud);
// pass.setFilterFieldName("y");
// pass.setFilterLimits(y_small, y_big);
// pass.filter(*cloud_out);
//
// pcl::io::savePCDFile<pcl::PointXYZ>("F://cout-saved//demo_filter.pcd", *cloud_out);
// cout << "there are " << cloud_out->points.size() << " points after filtering." << endl;
//
//}
//
//int main(int argc, char **argv)
//{
//
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);//声明数组
//
// if (pcl::io::loadPCDFile<pcl::PointXYZ>("F://cout-saved//flange.pcd", *cloud) == -1)
// {
// PCL_ERROR("Cloudn't read file!");
// return -1;
// }//读取点云文件
//
// void passFilter(cloud, 74.0, 86.0, -7.0, 15.0, 74.0, 80.0, *cloud_out);
//
//
//}//测试代码
//#include "pch.h"
//#include <iostream>
//#include <pcl/io/pcd_io.h>
//#include <pcl/point_types.h>
//
//int
//main(int argc, char** argv)
//{
// pcl::PointCloud<pcl::PointXYZ> cloud;
//
// // Fill in the cloud data
// cloud.width = 5;
// cloud.height = 1;
// cloud.is_dense = false;
// cloud.points.resize(cloud.width * cloud.height);
//
// for (size_t i = 0; i < cloud.points.size(); ++i)
// {
// cloud.points[i].x = 1024 * rand() / (RAND_MAX + 1.0f);
// cloud.points[i].y = 1024 * rand() / (RAND_MAX + 1.0f);
// cloud.points[i].z = 1024 * rand() / (RAND_MAX + 1.0f);
// }
//
// pcl::io::savePCDFileASCII("test_pcd.pcd", cloud);
// std::cerr << "Saved " << cloud.points.size() << " data points to test_pcd.pcd." << std::endl;
//
// for (size_t i = 0; i < cloud.points.size(); ++i)
// std::cerr << " " << cloud.points[i].x << " " << cloud.points[i].y << " " << cloud.points[i].z << std::endl;
// system("pause");
// return (0);
//}//
//#include <iostream> //标准输入输出流
//
//#include <pcl/io/pcd_io.h> //PCL的PCD格式文件的输入输出头文件
//
//#include <pcl/point_types.h> //PCL对各种格式的点的支持头文件
//
//#include <pcl/visualization/cloud_viewer.h>//点云查看窗口头文件
//
//int main(int argc, char** argv)
//
//{
//
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); // 创建点云(指针)
//
//
//
// if (pcl::io::loadPCDFile<pcl::PointXYZ>("C:\\Users\\Wzf\\Desktop\\rabbit\\rabbit_t.pcd", *cloud) == -1) //* 读入PCD格式的文件,如果文件不存在,返回-1
//
// {
//
// PCL_ERROR("Couldn't read file test_pcd.pcd \n"); //文件不存在时,返回错误,终止程序。
//
// return (-1);
//
// }
//
// pcl::visualization::CloudViewer viewer("Simple Cloud Viewer");//直接创造一个显示窗口
//
// viewer.showCloud(cloud);//再这个窗口显示点云
//
// while (!viewer.wasStopped())
//
// {
//
// }
//
// return (0);
//
//}点云数据txt转pcd格式
//#include "pch.h"
//#include<iostream>
//#include<fstream>
//#include<vector>
//#include<string>
//#include<pcl\io\pcd_io.h>
//#include<pcl\point_types.h>
//using namespace std;
//int main()
//{ //定义一种类型表示TXT中xyz
// typedef struct TXT_Point_XYZ
// {
// double x;
// double y;
// double z;
// }TOPOINT_XYZ;
// //读取txt文件
// int num_txt;
// FILE *fp_txt;
// TXT_Point_XYZ txt_points;
// vector<TXT_Point_XYZ> my_vTxtPoints;
// fp_txt = fopen("C://Users//HEHE//Desktop//Chair.txt","r");
// if (fp_txt)
// {
// while (fscanf(fp_txt, "%lf %lf %lf", &txt_points.x, &txt_points.y, &txt_points.z) != EOF)
// {//将点存入容器尾部
// my_vTxtPoints.push_back(txt_points);
// }
// }
// else
// cout << "读取txt文件失败"<<endl;
// num_txt = my_vTxtPoints.size();
// //写入点云数据
// pcl::PointCloud<pcl::PointXYZ> ::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// cloud->width = num_txt;
// cloud->height = 1;
// cloud->is_dense = false;
// cloud->points.resize(cloud->width*cloud->height);
// for (int i = 0; i < cloud->points.size(); ++i)
// {
// cloud->points[i].x = my_vTxtPoints[i].x;
// cloud->points[i].y = my_vTxtPoints[i].y;
// cloud->points[i].z = my_vTxtPoints[i].z;
// }
// pcl::io::savePCDFileASCII("C://Users//HEHE//Desktop//Chair.pcd", *cloud);
// cout<< "从 Chair.txt读取" << cloud->points.size() << "点写入Chair.pcd" << endl;
// //打印出写入的点 cout << "_________________________________" << endl;
// for (size_t i = 0; i < cloud->points.size(); ++i)
// cout << " " << cloud->points[i].x
// << " " << cloud->points[i].y
// << " " << cloud->points[i].z << endl;
// return 0;
//}体素滤波
//#include "pch.h"
//#include <iostream>
//#include <pcl/io/pcd_io.h>
//#include <pcl/point_types.h>
//#include <pcl/filters/voxel_grid.h>
//
//
//int
//main(int argc, char** argv)
//{
//
// pcl::PCLPointCloud2::Ptr cloud(new pcl::PCLPointCloud2());
// pcl::PCLPointCloud2::Ptr cloud_filtered(new pcl::PCLPointCloud2());
//
// //点云对象的读取
// pcl::PCDReader reader;
//
// reader.read("C://Users//HEHE//Desktop//Chair.pcd", *cloud); //读取点云到cloud中
//
// std::cerr << "PointCloud before filtering: " << cloud->width * cloud->height
// << " data points (" << pcl::getFieldsList(*cloud) << ").";
//
// /******************************************************************************
// 创建一个叶大小为1cm的pcl::VoxelGrid滤波器,
// **********************************************************************************/
// pcl::VoxelGrid<pcl::PCLPointCloud2> sor; //创建滤波对象
// sor.setInputCloud(cloud); //设置需要过滤的点云给滤波对象
// //sor.setLeafSize(0.01f, 0.01f, 0.01f); //设置滤波时创建的体素体积为1cm的立方体
// sor.setLeafSize(10.0f, 10.0f, 10.0f);
// sor.filter(*cloud_filtered); //执行滤波处理,存储输出
//
// std::cerr << "PointCloud after filtering: " << cloud_filtered->width * cloud_filtered->height
// << " data points (" << pcl::getFieldsList(*cloud_filtered) << ").";
//
// pcl::PCDWriter writer;
// writer.write("C://Users//HEHE//Desktop//Chair_downsampled.pcd", *cloud_filtered,
// Eigen::Vector4f::Zero(), Eigen::Quaternionf::Identity(), false);
//
// return (0);
//}statisticalOutlierRemoval滤波器移除离群点
//#include "pch.h"
//#include <iostream>
//#include <pcl/io/pcd_io.h>
//#include <pcl/point_types.h>
//#include <pcl/filters/statistical_outlier_removal.h>
//
//int
//main(int argc, char** argv)
//{
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>);
//
// // 定义读取对象
// pcl::PCDReader reader;
// // 读取点云文件
// reader.read<pcl::PointXYZ>("C://Users//HEHE//Desktop//Chair.pcd", *cloud);
//
// std::cerr << "Cloud before filtering: " << std::endl;
// std::cerr << *cloud << std::endl;
//
// // 创建滤波器,对每个点分析的临近点的个数设置为50 ,并将标准差的倍数设置为1 这意味着如果一
// //个点的距离超出了平均距离一个标准差以上,则该点被标记为离群点,并将它移除,存储起来
// pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor; //创建滤波器对象
// sor.setInputCloud(cloud); //设置待滤波的点云
// sor.setMeanK(50); //设置在进行统计时考虑查询点临近点数
// sor.setStddevMulThresh(1.0); //设置判断是否为离群点的阀值
// sor.filter(*cloud_filtered); //存储
//
// std::cerr << "Cloud after filtering: " << std::endl;
// std::cerr << *cloud_filtered << std::endl;
//
// pcl::PCDWriter writer;
// writer.write<pcl::PointXYZ>("C://Users//HEHE//Desktop//Chair_inliers.pcd", *cloud_filtered, false);
//
// sor.setNegative(true);
// sor.filter(*cloud_filtered);
// writer.write<pcl::PointXYZ>("C://Users//HEHE//Desktop//Chair_outliers.pcd", *cloud_filtered, false);
//
// return (0);
//}直通滤波算法
//#include "pch.h"
//#include <pcl/io/pcd_io.h> //文件输入输出
//#include <pcl/point_types.h> //点类型相关定义
//#include <pcl/visualization/cloud_viewer.h> //点云可视化相关定义
//#include <pcl/filters/passthrough.h> //直通滤波相关
//#include <pcl/common/common.h>
//#include <iostream>#include <vector>
//using namespace std;
//int main()
//{ //1.读取点云
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// if (pcl::io::loadPCDFile<pcl::PointXYZ>("C://Users//HEHE//Desktop//back_1.pcd", *cloud) == -1)
// {
// PCL_ERROR("Cloudn't read file!");
// return -1;
// } cout << "there are " << cloud->points.size()<<" points before filtering." << endl;
// //2.取得点云坐标极值
// pcl::PointXYZ minPt, maxPt; pcl::getMinMax3D(*cloud, minPt, maxPt);
// //3.直通滤波
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filter(new pcl::PointCloud<pcl::PointXYZ>);
// pcl::PassThrough<pcl::PointXYZ> pass; //创建滤波器对象
// pass.setInputCloud(cloud); //设置待滤波的点云
// pass.setFilterFieldName("x"); //设置在Z轴方向上进行滤波
// //pass.setFilterLimits(0, maxPt.z - 12); //设置滤波范围(从最高点向下12米去除)在该范围外的滤除掉
// //pass.setFilterLimits(0, 0.5);//点云中z坐标在括号范围外的点过滤掉 结果全是0
// pass.setFilterLimits(0, 20);
// pass.setFilterLimitsNegative(false); //保留 代表了是否显示被过滤掉的点,如果设置为true则将被过滤的以红色表示,没过滤的用绿色表示。默认是false.
// pass.filter(*cloud_filter); //滤波并存储
// //4.滤波结果保存
// pcl::io::savePCDFile<pcl::PointXYZ>("C://Users//HEHE//Desktop//demo_filter.pcd", *cloud_filter);
// cout << "there are " << cloud_filter->points.size() << " points after filtering." << endl;
// system("pause");
// return 0;
//}直通滤波算法
//#include "pch.h"
//#include <pcl/io/pcd_io.h> //文件输入输出
//#include <pcl/point_types.h> //点类型相关定义
//#include <pcl/visualization/cloud_viewer.h> //点云可视化相关定义
//#include <pcl/filters/passthrough.h> //直通滤波相关
//#include <pcl/common/common.h>
//#include <iostream>
//#include <vector>
//using namespace std;
//int main()
//{ //1.读取点云
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// if (pcl::io::loadPCDFile<pcl::PointXYZ>("C://Users//HEHE//Desktop//flange_filter2.pcd", *cloud) == -1)
// {
// PCL_ERROR("Cloudn't read file!");
// return -1;
// } cout << "there are " << cloud->points.size()<<" points before filtering." << endl;
// //2.取得点云坐标极值
// pcl::PointXYZ minPt, maxPt; pcl::getMinMax3D(*cloud, minPt, maxPt);
// //3.直通滤波
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filter(new pcl::PointCloud<pcl::PointXYZ>);
// pcl::PassThrough<pcl::PointXYZ> pass; //创建滤波器对象
// pass.setInputCloud(cloud); //设置待滤波的点云
// //第一步过滤上下Y上
// //pass.setFilterFieldName("y"); //设置在Z轴方向上进行滤波
// //pass.setFilterLimits(0, maxPt.z - 12); //设置滤波范围(从最高点向下12米去除)在该范围外的滤除掉
// //pass.setFilterLimits(0, 0.5);8//点云中z坐标在括号范围外的点过滤掉 结果全是0
// //pass.setFilterLimits(8, 13);
// //第二步过滤前后Z上
// //pass.setFilterFieldName("z");
// //pass.setFilterLimits(74.5, 85.5);
// //第三步:过滤左右X上
// pass.setFilterFieldName("x");
// pass.setFilterLimits(-10, 13.5);
// pass.setFilterLimitsNegative(false); //保留 代表了是否显示被过滤掉的点,如果设置为true则将被过滤的以红色表示,没过滤的用绿色表示。默认是false.
// pass.filter(*cloud_filter); //滤波并存储
// //4.滤波结果保存
// pcl::io::savePCDFile<pcl::PointXYZ>("C://Users//HEHE//Desktop//flange_filter3.pcd", *cloud_filter);
// cout << "there are " << cloud_filter->points.size() << " points after filtering." << endl;
// system("pause");
// return 0;
//}半径滤波
//#include "pch.h"
//#include <pcl/io/pcd_io.h> //文件输入输出
//#include <pcl/point_types.h> //点类型相关定义
//#include <pcl/visualization/cloud_viewer.h> //点云可视化相关定义
//#include <pcl/filters/radius_outlier_removal.h> //滤波相关
//#include <pcl/common/common.h>
//#include <iostream>
//
//using namespace std;
//
//int main()
//{
// //1.读取点云
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// pcl::PCDReader r;
// r.read<pcl::PointXYZ>("C://Users//HEHE//Desktop//flange_filter3_Radius_filter.pcd", *cloud);
// cout << "there are " << cloud->points.size() << " points before filtering." << endl;
//
// //2.半径滤波
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filter(new pcl::PointCloud<pcl::PointXYZ>);
// pcl::RadiusOutlierRemoval<pcl::PointXYZ> sor;
// sor.setInputCloud(cloud);//设置输入点云
// //第一次半径滤波
// //sor.setRadiusSearch(0.5);//设置在0.2米半径的范围内找邻近点
// //sor.setMinNeighborsInRadius(40);//设置查询点的邻近点集数小于15的删除
// sor.setRadiusSearch(0.2);//设置在0.2米半径的范围内找邻近点
// sor.setMinNeighborsInRadius(5);
// sor.setNegative(false);
// //sor.setKeepOrganized(true);//保持结构点云
// sor.filter(*cloud_filter);//应用滤波器
//
// //3.滤波结果保存
// pcl::PCDWriter w;
// w.writeASCII<pcl::PointXYZ>("C://Users//HEHE//Desktop//flange_filter3_Radius_filter2.pcd", *cloud_filter);
// cout << "there are " << cloud_filter->points.size() << " points after filtering." << endl;
//
// system("pause");
// return 0;
//}//#include "pch.h"
//#include <pcl/ModelCoefficients.h>
//#include <pcl/point_types.h>
//#include <pcl/io/pcd_io.h>
//#include <pcl/filters/extract_indices.h>
//#include <pcl/filters/voxel_grid.h>
//#include <pcl/features/normal_3d.h>
//#include <pcl/kdtree/kdtree.h>
//#include <pcl/sample_consensus/method_types.h>
//#include <pcl/sample_consensus/model_types.h>
//#include <pcl/segmentation/sac_segmentation.h>
//#include <pcl/segmentation/extract_clusters.h>
//
//
//int
//main(int argc, char** argv)
//{
// //读入点云数据table_scene_lms400.pcd
// pcl::PCDReader reader;
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>), cloud_f(new pcl::PointCloud<pcl::PointXYZ>);
// reader.read("C://Users//HEHE//Desktop//flange_filter3_Radius_filter2.pcd", *cloud);
// std::cout << "PointCloud before filtering has: " << cloud->points.size() << " data points." << std::endl; //*
// ///*从输入的.PCD文件载入数据后,我们创建了一个VoxelGrid滤波器对数据进行下采样,我们在这里进行下采样的原 因是来加速处理过程,越少的点意味着分割循环中处理起来越快。*/
// Create the filtering object: downsample the dataset using a leaf size of 1cm
// //pcl::VoxelGrid<pcl::PointXYZ> vg; //体素栅格下采样对象
// //pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>);
// //vg.setInputCloud(cloud);
// //vg.setLeafSize(0.01f, 0.01f, 0.01f); //设置采样的体素大小
// //vg.filter(*cloud_filtered); //执行采样保存数据
// //std::cout << "PointCloud after filtering has: " << cloud_filtered->points.size() << " data points." << std::endl; //*
//
// // Create the segmentation object for the planar model and set all the parameters
// pcl::SACSegmentation<pcl::PointXYZ> seg;//创建分割对象
// pcl::PointIndices::Ptr inliers(new pcl::PointIndices);
// pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients);
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_plane(new pcl::PointCloud<pcl::PointXYZ>());
// pcl::PCDWriter writer;
// seg.setOptimizeCoefficients(true); //设置对估计的模型参数进行优化处理
// seg.setModelType(pcl::SACMODEL_PLANE);//设置分割模型类别
// seg.setMethodType(pcl::SAC_RANSAC);//设置用哪个随机参数估计方法
// seg.setMaxIterations(100); //设置最大迭代次数
// seg.setDistanceThreshold(0.02); //设置判断是否为模型内点的距离阈值
//
// int i = 0, nr_points = (int) cloud->points.size();
// while (cloud ->points.size() > 0.3 * nr_points)
// {
// // Segment the largest planar component from the remaining cloud
// /*为了处理点云中包含多个模型,我们在一个循环中执行该过程,并在每次模型被提取后,我们保存剩余的点,进行迭代。模型内点通过分割过程获取,如下*/
// seg.setInputCloud(cloud);
// seg.segment(*inliers, *coefficients);
// if (inliers->indices.size() == 0)
// {
// std::cout << "Could not estimate a planar model for the given dataset." << std::endl;
// break;
// }
//
// //移去平面局内点,提取剩余点云
// pcl::ExtractIndices<pcl::PointXYZ> extract; //创建点云提取对象
// extract.setInputCloud(cloud); //设置输入点云
// extract.setIndices(inliers); //设置分割后的内点为需要提取的点集
// extract.setNegative(false); //设置提取内点而非外点
// // Get the points associated with the planar surface
// extract.filter(*cloud_plane); //提取输出存储到cloud_plane
// std::cout << "PointCloud representing the planar component: " << cloud_plane->points.size() << " data points." << std::endl;
//
// // Remove the planar inliers, extract the rest
// extract.setNegative(true);
// extract.filter(*cloud_f);
// *cloud = *cloud_f;
// }
//
// // Creating the KdTree object for the search method of the extraction
// pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>);
// tree->setInputCloud(cloud); //创建点云索引向量,用于存储实际的点云信息
//
// std::vector<pcl::PointIndices> cluster_indices;
// pcl::EuclideanClusterExtraction<pcl::PointXYZ> ec;
// ec.setClusterTolerance(4.0); //设置近邻搜索的搜索半径为2cm(源代码0.02)
// ec.setMinClusterSize(200);//设置一个聚类需要的最少点数目为100
// ec.setMaxClusterSize(25000);//设置一个聚类需要的最大点数目为25000
// ec.setSearchMethod(tree);//设置点云的搜索机制
// ec.setInputCloud(cloud);
// ec.extract(cluster_indices);//从点云中提取聚类,并将点云索引保存在cluster_indices中
//
// /*为了从点云索引向量中分割出每个聚类,必须迭代访问点云索引,每次创建一个新的点云数据集,并且将所有当前聚类的点写入到点云数据集中。*/
// //迭代访问点云索引cluster_indices,直到分割出所有聚类
// int j = 0;
// for (std::vector<pcl::PointIndices>::const_iterator it = cluster_indices.begin(); it != cluster_indices.end(); ++it)
// {
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_cluster(new pcl::PointCloud<pcl::PointXYZ>);
// //创建新的点云数据集cloud_cluster,将所有当前聚类写入到点云数据集中
// for (std::vector<int>::const_iterator pit = it->indices.begin(); pit != it->indices.end(); ++pit)
// cloud_cluster->points.push_back(cloud->points[*pit]); //*
// cloud_cluster->width = cloud_cluster->points.size();
// cloud_cluster->height = 1;
// cloud_cluster->is_dense = true;
//
// std::cout << "PointCloud representing the Cluster: " << cloud_cluster->points.size() << " data points." << std::endl;
// std::stringstream ss;
// ss << "C://Users//HEHE//Desktop//cloud_cluster_" << j << ".pcd";
// writer.writeASCII<pcl::PointXYZ>(ss.str(), *cloud_cluster, false); //*
// j++;
// }
//
// std::cout << "there are " << j << " yuan" << std::endl;
//
// system("pause");
//
// return (0);
//}欧式距离聚类,实现点云分割
//#include "pch.h"
//#include <pcl/ModelCoefficients.h>
//#include <pcl/point_types.h>
//#include <pcl/io/pcd_io.h>
//#include <pcl/filters/extract_indices.h>
//#include <pcl/filters/voxel_grid.h>
//#include <pcl/features/normal_3d.h>
//#include <pcl/kdtree/kdtree.h>
//#include <pcl/sample_consensus/method_types.h>
//#include <pcl/sample_consensus/model_types.h>
//#include <pcl/segmentation/sac_segmentation.h>
//#include <pcl/segmentation/extract_clusters.h>
//#include <iostream>
//using namespace std;
//
//int
//main(int argc, char** argv)
//{
// // 申明存储点云的对象.
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
//
// //读取Pcd文件
// //if (pcl::io::loadPCDFile<pcl::PointXYZ>("C://Users//HEHE//Desktop//flange_filter3_Radius_filter2.pcd", *cloud) == -1)
// if (pcl::io::loadPCDFile<pcl::PointXYZ>("F://cout-saved//back_1_remove.pcd", *cloud) == -1)
// {
// PCL_ERROR("Cloudn't read file!");
// return -1;
// } cout << "there are " << cloud->points.size()<<" points before filtering." << endl;
//
//
// // 建立kd-tree对象用来搜索 .
// pcl::search::KdTree<pcl::PointXYZ>::Ptr kdtree(new pcl::search::KdTree<pcl::PointXYZ>);
// kdtree->setInputCloud(cloud);
//
// // Euclidean 聚类对象.
// pcl::EuclideanClusterExtraction<pcl::PointXYZ> clustering;//类EuclideanClusterExtraction是基于欧式距离进行聚类分割的类
// clustering.setClusterTolerance(4.0);//设置在欧氏空间中所使用的搜索半径设置的过小可能导致聚类被划分到几个集群,设置的过大可能将聚类进行联通
// clustering.setMinClusterSize(100);// 设置聚类包含的的最小点数目
// clustering.setMaxClusterSize(25000); //设置聚类包含的的最大点数目
// clustering.setSearchMethod(kdtree);//类的关键成员函数
// clustering.setInputCloud(cloud);//指定输入的点云进行聚类分割
// std::vector<pcl::PointIndices> clusters;// cluster存储点云聚类分割的结果。PointIndices存储对应点集的索引
// clustering.extract(clusters);
//
// // For every cluster...
// int currentClusterNum = 1;
// for (std::vector<pcl::PointIndices>::const_iterator i = clusters.begin(); i != clusters.end(); ++i)
// {
// //添加所有的点云到一个新的点云中
// pcl::PointCloud<pcl::PointXYZ>::Ptr cluster(new pcl::PointCloud<pcl::PointXYZ>);
// for (std::vector<int>::const_iterator point = i->indices.begin(); point != i->indices.end(); point++)
// cluster->points.push_back(cloud->points[*point]);
// cluster->width = cluster->points.size();
// cluster->height = 1;
// cluster->is_dense = true;
//
// // 保存
// if (cluster->points.size() <= 0)
// break;
// std::cout << "Cluster " << currentClusterNum << " has " << cluster->points.size() << " points." << std::endl;
// std::string fileName = "F://cout-saved//cluster" + boost::to_string(currentClusterNum) + ".pcd";
// pcl::io::savePCDFileASCII(fileName, *cluster);
//
// currentClusterNum++;
// }
//}PCL寻找点云边界
//#include "pch.h"
//#include <iostream>
//#include <vector>
//#include <ctime>
//#include <boost/thread/thread.hpp>
//#include <pcl/io/pcd_io.h>
//#include <pcl/visualization/pcl_visualizer.h>
//#include <pcl/console/parse.h>
//#include <pcl/features/eigen.h>
//#include <pcl/features/feature.h>
//#include <pcl/features/normal_3d.h>
//#include <pcl/impl/point_types.hpp>
//#include <pcl/features/boundary.h>
//#include <pcl/visualization/cloud_viewer.h>
//using namespace std;
//
//int main(int argc, char **argv)
//{
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);//声明数组
//
// if (pcl::io::loadPCDFile<pcl::PointXYZ>("C://Users//HEHE//Desktop//back_1.pcd", *cloud) == -1)
// {
// PCL_ERROR("Cloudn't read file!");
// return -1;
// }
//
//
// std::cout << "points size is:" << cloud->size() << std::endl;
// pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
// pcl::PointCloud<pcl::Boundary> boundaries;//Boundary,表示点是否位于表面边界的描述的点结构
//
// pcl::BoundaryEstimation<pcl::PointXYZ, pcl::Normal, pcl::Boundary> est; //BoundaryEstimation使用角度标准估计一组点是否位于表面边界上
//
// pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>());
//
// pcl::KdTreeFLANN<pcl::PointXYZ> kdtree; //创建一个快速k近邻查询,查询的时候若该点在点云中,则第一个近邻点是其本身
// kdtree.setInputCloud(cloud);
// int k =2;
// float everagedistance =0;
// for (int i =0; i < cloud->size()/2;i++)
// {
// vector<int> nnh ; //表示定义一个容器nnh,容器内的值为int类型。(与数组类似,但是容器的大小可变)//索引
// vector<float> squaredistance;//欧式距离
// // pcl::PointXYZ p;
// // p = cloud->points[i];
// kdtree.nearestKSearch(cloud->points[i],k,nnh,squaredistance);
// everagedistance += sqrt(squaredistance[1]);
// // cout<<everagedistance<<endl;
// }
//
// everagedistance = everagedistance/(cloud->size()/2);
// cout<<"everage distance is : "<<everagedistance<<endl;
//
// pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> normEst; //其中pcl::PointXYZ表示输入类型数据,pcl::Normal表示输出类型,且pcl::Normal前三项是法向,最后一项是曲率
// normEst.setInputCloud(cloud);
// normEst.setSearchMethod(tree);
// // normEst.setRadiusSearch(2); //法向估计的半径
// normEst.setKSearch(15); //法向估计的点数
// normEst.compute(*normals);
// cout << "normal size is " << normals->size() << endl;
//
// //normal_est.setViewPoint(0,0,0); //这个应该会使法向一致
// est.setInputCloud(cloud);
// est.setInputNormals(normals);
// // est.setAngleThreshold(90);
// // est.setSearchMethod (pcl::search::KdTree<pcl::PointXYZ>::Ptr (new pcl::search::KdTree<pcl::PointXYZ>));
// est.setSearchMethod(tree);
// est.setKSearch(160); //一般这里的数值越高,最终边界识别的精度越好 //表示计算点云法向量时,搜索的点云个数
// //est.setRadiusSearch(everagedistance*10); //搜索半径
// est.compute(boundaries);
//
// pcl::PointCloud<pcl::PointXYZ>::Ptr boundPoints(new pcl::PointCloud<pcl::PointXYZ>);
// pcl::PointCloud<pcl::PointXYZ> noBoundPoints;
// int countBoundaries = 0;
// for (int i = 0; i < cloud->size(); i++)
// {
// uint8_t x = (boundaries.points[i].boundary_point);
// int a = static_cast<int>(x); //该函数的功能是强制类型转换
// if (a == 1)
// {
// // boundPoints.push_back(cloud->points[i]);
// (*boundPoints).push_back(cloud->points[i]);
// countBoundaries++;
// }
// else
// noBoundPoints.push_back(cloud->points[i]);
//
// }
// std::cout << "boudary size is:" << countBoundaries << std::endl;
//
// pcl::io::savePCDFileASCII("C://Users//HEHE//Desktop//boudary.pcd", *boundPoints);
// pcl::io::savePCDFileASCII("C://Users//HEHE//Desktop//NoBoundpoints.pcd", noBoundPoints);
// pcl::visualization::CloudViewer viewer("test");
// viewer.showCloud(boundPoints);
// while (!viewer.wasStopped())
// {
// }
// return 0;
//}2边界
//#include "pch.h"
//#include <iostream>
//#include <pcl/console/parse.h>
//#include <pcl/filters/extract_indices.h>
//#include <pcl/io/pcd_io.h>
//#include <pcl/point_types.h>
//#include <pcl/visualization/pcl_visualizer.h>
//#include <boost/thread/thread.hpp>
//#include <pcl/features/boundary.h>
//#include <math.h>
//#include <boost/make_shared.hpp>
//#include <pcl/point_cloud.h>
//#include <pcl/visualization/cloud_viewer.h>
//#include <pcl/visualization/range_image_visualizer.h>
//#include <pcl/features/normal_3d.h>
//#include <pcl/filters/covariance_sampling.h>
//#include <pcl/filters/normal_space.h>
//#include <pcl/kdtree/kdtree_flann.h>
//#include <pcl/io/ply_io.h>
//#include <pcl/filters/statistical_outlier_removal.h>
//int estimateBorders(pcl::PointCloud<pcl::PointXYZ>::Ptr &cloud,float re,float reforn)
//{
// pcl::PointCloud<pcl::Boundary> boundaries; //保存边界估计结果
// pcl::BoundaryEstimation<pcl::PointXYZ, pcl::Normal, pcl::Boundary> boundEst; //定义一个进行边界特征估计的对象
// pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> normEst; //定义一个法线估计的对象
// pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>); //保存法线估计的结果
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_boundary (new pcl::PointCloud<pcl::PointXYZ>);
// normEst.setInputCloud(pcl::PointCloud<pcl::PointXYZ>::Ptr(cloud));
// normEst.setRadiusSearch(reforn); //设置法线估计的半径
// normEst.compute(*normals); //将法线估计结果保存至normals
// //输出法线的个数
// std:cout<<"reforn: "<<reforn<<std::endl;
// std::cerr << "normals: " << normals->size() << std::endl;
// boundEst.setInputCloud(cloud); //设置输入的点云
// boundEst.setInputNormals(normals); //设置边界估计的法线,因为边界估计依赖于法线
// boundEst.setRadiusSearch(re); //设置边界估计所需要的半径
// boundEst.setAngleThreshold(M_PI/4); //边界估计时的角度阈值
// boundEst.setSearchMethod(pcl::search::KdTree<pcl::PointXYZ>::Ptr (new pcl::search::KdTree<pcl::PointXYZ>)); //设置搜索方式KdTree
// boundEst.compute(boundaries); //将边界估计结果保存在boundaries
// //输出边界点的个数
// std::cerr << "boundaries: " <<boundaries.points.size() << std::endl;
// //存储估计为边界的点云数据,将边界结果保存为pcl::PointXYZ类型
// for(int i = 0; i < cloud->points.size(); i++)
// {
// if(boundaries[i].boundary_point > 0)
// {
// cloud_boundary->push_back(cloud->points[i]);
// }
// }
// //可视化
// boost::shared_ptr<pcl::visualization::PCLVisualizer> MView (new pcl::visualization::PCLVisualizer ("点云库PCL从入门到精通案例"));
// int v1(0);
// MView->createViewPort (0.0, 0.0, 0.5, 1.0, v1);
// MView->setBackgroundColor (0.3, 0.3, 0.3, v1);
// MView->addText ("Raw point clouds", 10, 10, "v1_text", v1);
// int v2(0);
// MView->createViewPort (0.5, 0.0, 1, 1.0, v2);
// MView->setBackgroundColor (0.5, 0.5, 0.5, v2);
// MView->addText ("Boudary point clouds", 10, 10, "v2_text", v2);
// MView->addPointCloud<pcl::PointXYZ> (cloud, "sample cloud",v1);
// MView->addPointCloud<pcl::PointXYZ> (cloud_boundary, "cloud_boundary",v2);
// MView->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_COLOR, 1,0,0, "sample cloud",v1);
// MView->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_COLOR, 0,1,0, "cloud_boundary",v2);
// MView->addCoordinateSystem (1.0); MView->initCameraParameters ();
// MView->spin(); return 0;
//}
//int main(int argc, char** argv)
// {
// //srand(time(NULL));
// float re,reforn;
// re=std::atof(argv[2]);
// reforn=std::atof(argv[3]);
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_src (new pcl::PointCloud<pcl::PointXYZ>);
// //Laden der PCD-Files
// pcl::io::loadPCDFile (argv[1], *cloud_src);
// // 创建滤波器对象
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>);
// pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor;
// sor.setInputCloud (cloud_src);
// sor.setMeanK (100);//寻找每个点的50个最近邻点
// sor.setStddevMulThresh (1.0);//一个点的最近邻距离超过全局平均距离的一个标准差以上,就会舍弃
// sor.filter (*cloud_filtered);
// std::cout<<"cloud_src: "<<cloud_src->points.size()<<std::endl;
// std::cout<<"cloud_filtered: "<<cloud_filtered->points.size()<<std::endl;
// estimateBorders(cloud_filtered,re,reforn);
// return 0;
//}//#include "pch.h"
//#include <iostream>
//#include <vector>
//#include <ctime>
//#include <boost/thread/thread.hpp>
//#include <pcl/io/pcd_io.h>
//#include <pcl/visualization/pcl_visualizer.h>
//#include <pcl/console/parse.h>
//#include <pcl/features/eigen.h>
//#include <pcl/features/feature.h>
//#include <pcl/features/normal_3d.h>
//#include <pcl/impl/point_types.hpp>
//#include <pcl/features/boundary.h>
//#include <pcl/visualization/cloud_viewer.h>
//using namespace std;
//
//int main(int argc, char **argv)
//{
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// // if (pcl::io::loadPCDFile<pcl::PointXYZ>("/home/yxg/pcl/pcd/mid.pcd",*cloud) == -1)
// if (pcl::io::loadPCDFile<pcl::PointXYZ>("F://cout-saved//back_1.pcd", *cloud) == -1)
// //if (pcl::io::loadPCDFile<pcl::PointXYZ>(argv[1], *cloud) == -1)
// {
// PCL_ERROR("COULD NOT READ FILE mid.pcl \n");
// return (-1);
// }
//
// std::cout << "points sieze is:" << cloud->size() << std::endl;
// pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
// pcl::PointCloud<pcl::Boundary> boundaries;
// pcl::BoundaryEstimation<pcl::PointXYZ, pcl::Normal, pcl::Boundary> est;
// pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>()); //创建kdtree搜索对象
// /*
// pcl::KdTreeFLANN<pcl::PointXYZ> kdtree; //创建一个快速k近邻查询,查询的时候若该点在点云中,则第一个近邻点是其本身
// kdtree.setInputCloud(cloud); //设置查询空间
// int k =2;
// float everagedistance =0;
// for (int i =0; i < cloud->size()/2;i++)
// {
// vector<int> nnh ;
// vector<float> squaredistance;
// // pcl::PointXYZ p;
// // p = cloud->points[i];
// kdtree.nearestKSearch(cloud->points[i],k,nnh,squaredistance);
// everagedistance += sqrt(squaredistance[1]);
// // cout<<everagedistance<<endl;
// }
//
// everagedistance = everagedistance/(cloud->size()/2);
// cout<<"everage distance is : "<<everagedistance<<endl;
//
//*/
//
//
//
// pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> normEst; //其中pcl::PointXYZ表示输入类型数据,pcl::Normal表示输出类型,且pcl::Normal前三项是法向,最后一项是曲率
// normEst.setInputCloud(cloud);
// normEst.setSearchMethod(tree);
// std::cerr << "构建法向量" << endl;
// normEst.setRadiusSearch(0.3); //法向估计的半径
// //normEst.setKSearch(20); //法向估计的点数
// normEst.compute(*normals);
// cout << "normal size is " << normals->size() << endl;
//
// //normal_est.setViewPoint(0,0,0); //这个应该会使法向一致
// est.setInputCloud(cloud);
// est.setInputNormals(normals);
// est.setAngleThreshold(M_PI / 3.0);
// // est.setSearchMethod (pcl::search::KdTree<pcl::PointXYZ>::Ptr (new pcl::search::KdTree<pcl::PointXYZ>));
// est.setSearchMethod(tree);
// //est.setKSearch(500); //一般这里的数值越高,最终边界识别的精度越好
// est.setRadiusSearch(1); //搜索半径
// est.compute(boundaries);
//
//
// // pcl::PointCloud<pcl::PointXYZ> boundPoints;
// pcl::PointCloud<pcl::PointXYZ> boundPoints;
// pcl::PointCloud<pcl::PointXYZ>::Ptr noBoundPoints(new pcl::PointCloud<pcl::PointXYZ>);
//
// int countBoundaries = 0;
// for (int i = 0; i < cloud->size(); i++) {
// uint8_t x = (boundaries.points[i].boundary_point);
// int a = static_cast<int>(x); //该函数的功能是强制类型转换
// if (a == 1)
// {
// // boundPoints.push_back(cloud->points[i]);
// boundPoints.points.push_back(cloud->points[i]);
// countBoundaries++;
// }
// else
// noBoundPoints->points.push_back(cloud->points[i]);
//
// }
//
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloudptr(new pcl::PointCloud<pcl::PointXYZ>);
// cloudptr = boundPoints.makeShared();
// cloudptr->width = cloudptr->size();
// cloudptr->height = 1;
//
// std::cout << "boudary size is:" << countBoundaries << std::endl;
// // pcl::io::savePCDFileASCII("boudary.pcd",boundPoints);
// std::cerr << "存储文件" << std::endl;
// std::cerr << cloudptr->size() << " " << cloudptr->width << " " << cloudptr->height << endl;
// pcl::io::savePCDFileBinary("F://cout-saved//boudary.pcd", *cloudptr);
//
// noBoundPoints->width = noBoundPoints->size();
// noBoundPoints->height = 1;
// std::cerr << "存储非边界点文件" << std::endl;
// std::cerr << noBoundPoints->size() << endl;
// pcl::io::savePCDFileBinary("F://cout-saved//NoBoundpoints.pcd", *noBoundPoints);
//
// //可视化
// pcl::visualization::PCLVisualizer viewer("视窗");
// viewer.setBackgroundColor(0, 0, 0);
//
// int v1(0);
// int v2(1);
// viewer.createViewPort(0.0, 0.0, 0.5, 1.0, v1);
// viewer.createViewPort(0.5, 0.0, 1.0, 1.0, v2);
//
// pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZ> fildColor(cloudptr, "z");//按照z字段进行渲染
// pcl::visualization::PointCloudColorHandlerGenericField<pcl::PointXYZ> fildColor_r(cloud, "z");//按照z字段进行渲染
//
// viewer.addPointCloud<pcl::PointXYZ>(cloudptr, fildColor, "sample", v1);//显示点云,其中fildColor为颜色显示
// viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample");//设置点云大小
//
// viewer.addPointCloud<pcl::PointXYZ>(cloud, fildColor_r, "sample_1", v2);//显示点云,其中fildColor为颜色显示
// viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1, "sample_1");//设置点云大小
// while (!viewer.wasStopped())
// {
// viewer.spinOnce();
// }
// return (0);
//}
//#include"pch.h"
//#include <iostream>
//#include <pcl/ModelCoefficients.h>
//#include <pcl/io/pcd_io.h>
//#include <pcl/point_types.h>
//#include <pcl/sample_consensus/method_types.h> //随机参数估计方法头文件
//#include <pcl/sample_consensus/model_types.h> //模型定义头文件
//#include <pcl/segmentation/sac_segmentation.h> //基于采样一致性分割的类的头文件
//using namespace std;
//int
//main(int argc, char** argv)
//{
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
//
// if (pcl::io::loadPCDFile<pcl::PointXYZ>("C://Users//HEHE//Desktop//cluster1.pcd", *cloud) == -1)
// {
// PCL_ERROR("Cloudn't read file!");
// return -1;
// } cout << "there are points size is " << cloud->points.size()<< endl;
// // 设置几个局外点,即重新设置几个点的z值,使其偏离z为1的平面
// cloud->points[0].z = 2.0;
// cloud->points[3].z = -2.0;
// cloud->points[6].z = 4.0;
// std::cerr << "Point cloud data: " << cloud->points.size() << " points" << std::endl; //打印
// for (size_t i = 0; i < cloud->points.size(); ++i)
// std::cerr << " " << cloud->points[i].x << " "
// << cloud->points[i].y << " "
// << cloud->points[i].z << std::endl;
// //创建分割时所需要的模型系数对象,coefficients及存储内点的点索引集合对象inliers
// pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients);
// pcl::PointIndices::Ptr inliers(new pcl::PointIndices);
// // 创建分割对象
// pcl::SACSegmentation<pcl::PointXYZ> seg;
// // 可选择配置,设置模型系数需要优化
// seg.setOptimizeCoefficients(true);
// // 必要的配置,设置分割的模型类型,所用的随机参数估计方法,距离阀值,输入点云
// seg.setModelType(pcl::SACMODEL_PLANE);
// //设置模型类型
// seg.setMethodType(pcl::SAC_RANSAC);
// //设置随机采样一致性方法类型
// seg.setDistanceThreshold(0.01);
// //设定距离阀值,距离阀值决定了点被认为是局内点是必须满足的条件,表示点到估计模型的距离最大值,
// seg.setInputCloud(cloud);
// //引发分割实现,存储分割结果到点几何inliers及存储平面模型的系数coefficients
// seg.segment(*inliers, *coefficients);
// if (inliers->indices.size() == 0)
// {
// PCL_ERROR("Could not estimate a planar model for the given dataset.");
// return (-1);
// }
// //打印出平面模型
// std::cerr << "Model coefficients: " << coefficients->values[0] << " "
// << coefficients->values[1] << " "
// << coefficients->values[2] << " "
// << coefficients->values[3] << std::endl;
// std::cerr << "Model inliers: " << inliers->indices.size() << std::endl;
// for (size_t i = 0; i < inliers->indices.size(); ++i)
// std::cerr << inliers->indices[i] << " " << cloud->points[inliers->indices[i]].x << " "
// << cloud->points[inliers->indices[i]].y << " "
// << cloud->points[inliers->indices[i]].z << std::endl;
// return (0);
//}//删除pcd格式的强度信息
//#include "pch.h"
//#include <iostream>
//#include <string.h>
//#include <pcl/io/auto_io.h>
//
//int main(int argc, char** argv)
//{
// std::string filename = "F:\\cout-saved\\back_1.pcd";
// pcl::PointCloud<pcl::PointXYZI>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZI>);
// if (pcl::io::loadPCDFile(filename, *cloud) < 0)
// {
// std::cout << "open file error" << std::endl;
// Sleep(3000);
// return -1;
// }
//
// pcl::PointCloud<pcl::PointXYZ>::Ptr new_cloud(new pcl::PointCloud<pcl::PointXYZ >);
// new_cloud->width = cloud->width;
// new_cloud->height = cloud->height;
// new_cloud->points.resize(cloud->points.size());
// for (int i = 0; i < cloud->points.size(); ++i)
// {
// new_cloud->points[i].x = cloud->points[i].x;
// new_cloud->points[i].y = cloud->points[i].y;
// new_cloud->points[i].z = cloud->points[i].z;
// }
//
// if (pcl::io::savePCDFile("F:\\cout-saved\\back_1_remove.pcd", *new_cloud) < 0)
// {
// std::cout << "save file error" << std::endl;
// Sleep(3000);
// return -1;
// }
// else
// {
// std::cout << "save file success" << std::endl;
// Sleep(3000);
// return 0;
// }
//}
//
//#include "pch.h"
//#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>
//
//typedef pcl::PointXYZ PointT;
//
//int
//main(int argc, char** argv)
//{
// // All the objects needed
// pcl::PCDReader reader; //PCD文件读取对象
// pcl::PassThrough<PointT> pass; //直通滤波对象
// pcl::NormalEstimation<PointT, pcl::Normal> ne; //法线估计对象
// pcl::SACSegmentationFromNormals<PointT, pcl::Normal> seg; //分割对象
// pcl::PCDWriter writer; //PCD文件读取对象
// pcl::ExtractIndices<PointT> extract; //点提取对象
// pcl::ExtractIndices<pcl::Normal> extract_normals; ///点提取对象
// pcl::search::KdTree<PointT>::Ptr tree(new pcl::search::KdTree<PointT>());
//
// // Datasets
// pcl::PointCloud<PointT>::Ptr cloud(new pcl::PointCloud<PointT>);
// pcl::PointCloud<PointT>::Ptr cloud_filtered(new pcl::PointCloud<PointT>);
// pcl::PointCloud<pcl::Normal>::Ptr cloud_normals(new pcl::PointCloud<pcl::Normal>);
// pcl::PointCloud<PointT>::Ptr cloud_filtered2(new pcl::PointCloud<PointT>);
// pcl::PointCloud<pcl::Normal>::Ptr cloud_normals2(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);
//
// // Read in the cloud data
// reader.read("F://cout-saved//back_1_remove.pcd", *cloud);
// std::cerr << "PointCloud has: " << cloud->points.size() << " data points." << std::endl;
//
// // 直通滤波,将Z轴不在(0,1.5)范围的点过滤掉,将剩余的点存储到cloud_filtered对象中
// pass.setInputCloud(cloud);
// pass.setFilterFieldName("z");
// pass.setFilterLimits(74.5, 85.5);
// pass.filter(*cloud_filtered);
// std::cerr << "PointCloud after filtering has: " << cloud_filtered->points.size() << " data points." << std::endl;
//
// // 过滤后的点云进行法线估计,为后续进行基于法线的分割准备数据
// ne.setSearchMethod(tree);
// ne.setInputCloud(cloud_filtered);
// ne.setKSearch(50);
// ne.compute(*cloud_normals);
//
// // Create the segmentation object for the planar model and set all the parameters
// seg.setOptimizeCoefficients(true);
// seg.setModelType(pcl::SACMODEL_NORMAL_PLANE);
// seg.setNormalDistanceWeight(0.1);
// seg.setMethodType(pcl::SAC_RANSAC);
// seg.setMaxIterations(100);
// seg.setDistanceThreshold(0.03);
// seg.setInputCloud(cloud_filtered);
// seg.setInputNormals(cloud_normals);
// //获取平面模型的系数和处在平面的内点
// seg.segment(*inliers_plane, *coefficients_plane);
// std::cerr << "Plane coefficients: " << *coefficients_plane << std::endl;
//
// // 从点云中抽取分割的处在平面上的点集
// extract.setInputCloud(cloud_filtered);
// extract.setIndices(inliers_plane);
// extract.setNegative(false);
//
// // 存储分割得到的平面上的点到点云文件
// pcl::PointCloud<PointT>::Ptr cloud_plane(new pcl::PointCloud<PointT>());
// extract.filter(*cloud_plane);
// std::cerr << "PointCloud representing the planar component: " << cloud_plane->points.size() << " data points." << std::endl;
// writer.write("F://cout-saved//table_scene_mug_stereo_textured_plane.pcd", *cloud_plane, false);
//
// // Remove the planar inliers, extract the rest
// extract.setNegative(true);
// extract.filter(*cloud_filtered2);
// extract_normals.setNegative(true);
// extract_normals.setInputCloud(cloud_normals);
// extract_normals.setIndices(inliers_plane);
// extract_normals.filter(*cloud_normals2);
//
// // 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(10000); //设置迭代的最大次数10000
// seg.setDistanceThreshold(0.05); //设置内点到模型的距离允许最大值
// seg.setRadiusLimits(0, 0.1); //设置估计出的圆柱模型的半径的范围
// seg.setInputCloud(cloud_filtered2);
// seg.setInputNormals(cloud_normals2);
//
// // 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(cloud_filtered2);
// 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;
// writer.write("F://cout-saved//table_scene_mug_stereo_textured_cylinder.pcd", *cloud_cylinder, false);
// }
// return (0);
//}//#include "pch.h"
//#include <pcl/io/pcd_io.h> //文件输入输出
//#include <pcl/point_types.h> //点类型相关定义
//#include <pcl/visualization/cloud_viewer.h> //点云可视化相关定义
//#include <pcl/filters/radius_outlier_removal.h> //滤波相关
//#include <pcl/common/common.h>
//#include <iostream>
//
//using namespace std;
//
//int main()
//{
// //1.读取点云
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// pcl::PCDReader r;
// r.read<pcl::PointXYZ>("F://cout-saved//back_1.pcd", *cloud);
// cout << "there are " << cloud->points.size() << " points before filtering." << endl;
//
// //2.半径滤波
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filter(new pcl::PointCloud<pcl::PointXYZ>);
// pcl::RadiusOutlierRemoval<pcl::PointXYZ> sor;
// sor.setInputCloud(cloud);
// //sor.setRadiusSearch(0.02);//0.02米
// sor.setRadiusSearch(0.8);//搜查半径0.8mm
// sor.setMinNeighborsInRadius(100);
// sor.setNegative(false);
// sor.filter(*cloud_filter);
//
// //3.滤波结果保存
// pcl::PCDWriter w;
// w.writeASCII<pcl::PointXYZ>("F://cout-saved//back_1_radius.pcd", *cloud_filter);
// cout << "there are " << cloud_filter->points.size() << " points after filtering." << endl;
//
// system("pause");
// return 0;
//}统计滤波
//#include "pch.h"
//#include <iostream>
//#include <pcl/io/pcd_io.h>
//#include <pcl/point_types.h>
//#include <pcl/filters/statistical_outlier_removal.h>
//int
//main (int argc, char** argv)
//{
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered (new pcl::PointCloud<pcl::PointXYZ>); // 定义读取对象
// pcl::PCDReader reader; // 读取点云文件
// reader.read<pcl::PointXYZ> ("F://cout-saved//back_1.pcd", *cloud);
// std::cerr << "Cloud before filtering: " << std::endl;
// std::cerr << *cloud << std::endl;
// // 创建滤波器,对每个点分析的临近点的个数设置为50 ,并将标准差的倍数设置为1 这意味着如果一
// //个点的距离超出了平均距离一个标准差以上,则该点被标记为离群点,并将它移除,存储起来
// pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor; //创建滤波器对象
// sor.setInputCloud (cloud); //设置待滤波的点云
// //sor.setMeanK (100); //设置在进行统计时考虑查询点临近点数
// //sor.setStddevMulThresh (1.0); //back_1_inliers.pcd //设置判断是否为离群点的阀值
//
// sor.setMeanK (250); //设置在进行统计时考虑查询点临近点数
// //sor.setStddevMulThresh (1.0); //2
// //sor.setStddevMulThresh(2.0);//3
// //sor.setStddevMulThresh(0.6);//4
// sor.setStddevMulThresh(0.3);//4
// sor.filter (*cloud_filtered); //存储
// std::cerr << "Cloud after filtering: " << std::endl;
// std::cerr << *cloud_filtered << std::endl;
// pcl::PCDWriter writer; writer.write<pcl::PointXYZ> ("F://cout-saved//back_1_inliers5.pcd", *cloud_filtered, false);
// sor.setNegative (true);
// sor.filter (*cloud_filtered);
// writer.write<pcl::PointXYZ> ("F://cout-saved//back_1_outliers5.pcd", *cloud_filtered, false);
// return (0);
//}分离地面
//#include "pch.h"
//#include <iostream>
//#include <pcl/ModelCoefficients.h>
//#include <pcl/io/pcd_io.h>
//#include <pcl/point_types.h>
//#include <pcl/sample_consensus/method_types.h>
//#include <pcl/sample_consensus/model_types.h>
//#include <pcl/segmentation/sac_segmentation.h>
//#include <pcl/visualization/cloud_viewer.h>
//#include <pcl/filters/extract_indices.h>
//void viewerOneOff(pcl::visualization::PCLVisualizer& viewer)
//{
// viewer.setBackgroundColor(0,0,1);
//}
//int main (int argc, char** argv)
//{
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>);
// pcl::PCDReader reader; // 读入点云PCD文件
// reader.read("F://cout-saved//back_1_inliers5.pcd",*cloud);
// std::cerr << "Point cloud data: " << cloud->points.size () << " points" << std::endl;
// pcl::ModelCoefficients::Ptr coefficients (new pcl::ModelCoefficients);
// pcl::PointIndices::Ptr inliers (new pcl::PointIndices);
// // Create the segmentation object
// pcl::SACSegmentation<pcl::PointXYZ> seg;//创建一个分割方法
// // pcl::ModelCoefficients coefficients; //申明模型的参数
// // pcl::PointIndices inliers; //申明存储模型的内点的索引
// // Optional
// seg.setOptimizeCoefficients (true);//选择最优化参数的因子
// // Mandatory
// seg.setModelType (pcl::SACMODEL_PLANE);//平面模型
// seg.setMethodType (pcl::SAC_RANSAC);//分割平面模型所用的分割方法
// //在这个Plane Model Segmentation算法里,Ransac为了找到点云的平面,不停的改变平面模型(ax + by + cz + d = 0)的参数:a, b, c和d。
// //经过多次调参后,找出哪一组的参数能使得这个模型一定程度上拟合最多的点。
// //这个程度就是由distance threshold这个参数来设置。那找到这组参数后,这些能够被拟合的点就是平面的点
// //设置误差容忍范围 设置最小的距离阈值 单位mm(根据自己的数据单位为mm,所以此处也是毫米单位)
// seg.setDistanceThreshold (0.4);//把distance threshold调大,离平面更远的点也被算进平面来。distance threshold 可以等同于平面厚度阈值
// seg.setInputCloud (cloud);//设置输入的点云
// seg.segment (*inliers, *coefficients);
// if (inliers->indices.size () == 0)
// {
// PCL_ERROR ("Could not estimate a planar model for the given dataset.");
// return (-1);
// }
// // 提取地面
// pcl::ExtractIndices<pcl::PointXYZ> extract;//ExtractIndices滤波器,基于某一分割算法提取点云中的一个子集
// extract.setInputCloud (cloud);
// extract.setIndices (inliers);//设置分割后的内点为需要提取的点集
// extract.filter (*cloud_filtered);
// std::cerr << "Ground cloud after filtering: " << std::endl;
// std::cerr << *cloud_filtered << std::endl;
// pcl::PCDWriter writer;
// writer.write<pcl::PointXYZ> ("F://cout-saved//back_1_inliers5_ground.pcd", *cloud_filtered, false);
// // 提取除地面外的物体
// extract.setNegative (true);//设置提取内点而非外点 或者相反
// extract.filter (*cloud_filtered);
// std::cerr << "Object cloud after filtering: " << std::endl;
// std::cerr << *cloud_filtered << std::endl;
// writer.write<pcl::PointXYZ> ("F://cout-saved//back_1_inliers5_No_ground.pcd", *cloud_filtered, false);
// // 点云可视化
// pcl::visualization::CloudViewer viewer("Filtered");
// viewer.showCloud(cloud_filtered);
// viewer.runOnVisualizationThreadOnce(viewerOneOff);
// while(!viewer.wasStopped())
// { }
// return (0);
//}
////#include "pch.h"
//#include <iostream> //标准C++库中的输入输出类相关头文件。
//#include <pcl/io/pcd_io.h> //pcd 读写类相关的头文件。
//#include <pcl/point_types.h> //PCL中支持的点类型头文件。
//#include <pcl/common/common.h>
//double Max_X;
//double Min_X;
//double Max_Z;
//double Min_Z;
//int
//main(int argc, char** argv)
//{
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>); // 定义读取对象
// pcl::PCDReader reader; // 读取点云文件
// reader.read<pcl::PointXYZ>("F://cout-saved//back_1.pcd", *cloud);
// std::cerr << "Cloud before filtering: " << std::endl;
// std::cerr << *cloud << std::endl;
// //定义储存极值的两个点
// pcl::PointXYZ minpt, maxpt;
// pcl::getMinMax3D(*cloud, minpt, maxpt);
// //输出结果
// /*std::cout << "max:x" << maxpt.x << std::endl;
// std::cout << "max:y" << maxpt.y << std::endl;
// std::cout << "max:z" << maxpt.z << std::endl;
// std::cout << "min:x" << minpt.x << std::endl;
// std::cout << "min:y" << minpt.y << std::endl;
// std::cout << "min:z" << minpt.z << std::endl;*/
// Max_X = maxpt.x;
// Min_X = minpt.x;
// Max_Z = maxpt.z;
// Min_Z = minpt.z;
// std::cout << "max:X : " << Max_X << std::endl;
// std::cout << "min:X : " << Min_X << std::endl;
// std::cout << "max:Z : " << Max_Z << std::endl;
// std::cout << "min:Z : " << Min_Z << std::endl;
//
//
//
// system("pause");
// return 0;
//}PCL寻找点云边界
//#include "pch.h"
//#include <iostream>
//#include <vector>
//#include <ctime>
//#include <boost/thread/thread.hpp>
//#include <pcl/io/pcd_io.h>
//#include <pcl/visualization/pcl_visualizer.h>
//#include <pcl/console/parse.h>
//#include <pcl/features/eigen.h>
//#include <pcl/features/feature.h>
//#include <pcl/features/normal_3d.h>
//#include <pcl/impl/point_types.hpp>
//#include <pcl/features/boundary.h>
//#include <pcl/visualization/cloud_viewer.h>
//using namespace std;
//
//int main(int argc, char **argv)
//{
// pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);//声明数组
//
// if (pcl::io::loadPCDFile<pcl::PointXYZ>("F://cout-saved//back_1.pcd", *cloud) == -1)
// {
// PCL_ERROR("Cloudn't read file!");
// return -1;
// }
//
//
// std::cout << "points size is:" << cloud->size() << std::endl;
// pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
// pcl::PointCloud<pcl::Boundary> boundaries;//Boundary,表示点是否位于表面边界的描述的点结构
//
// pcl::BoundaryEstimation<pcl::PointXYZ, pcl::Normal, pcl::Boundary> est; //BoundaryEstimation使用角度标准估计一组点是否位于表面边界上
//
// pcl::search::KdTree<pcl::PointXYZ>::Ptr tree(new pcl::search::KdTree<pcl::PointXYZ>());
//
// pcl::KdTreeFLANN<pcl::PointXYZ> kdtree; //创建一个快速k近邻查询,查询的时候若该点在点云中,则第一个近邻点是其本身
// kdtree.setInputCloud(cloud);
//
// pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> normEst; //其中pcl::PointXYZ表示输入类型数据,pcl::Normal表示输出类型,且pcl::Normal前三项是法向,最后一项是曲率
// normEst.setInputCloud(cloud);
// normEst.setSearchMethod(tree);
//
// normEst.setKSearch(15); //法向估计的点数
// normEst.compute(*normals);
// cout << "normal size is " << normals->size() << endl;
//
// //normal_est.setViewPoint(0,0,0); //这个应该会使法向一致
// est.setInputCloud(cloud);
// est.setInputNormals(normals);
// // est.setAngleThreshold(90);
//
// est.setSearchMethod(tree);
// est.setKSearch(160); //一般这里的数值越高,最终边界识别的精度越好 //表示计算点云法向量时,搜索的点云个数
//
// est.compute(boundaries);
//
// pcl::PointCloud<pcl::PointXYZ>::Ptr boundPoints(new pcl::PointCloud<pcl::PointXYZ>);
// pcl::PointCloud<pcl::PointXYZ> noBoundPoints;
// int countBoundaries = 0;
// for (int i = 0; i < cloud->size(); i++)
// {
// uint8_t x = (boundaries.points[i].boundary_point);
// int a = static_cast<int>(x); //该函数的功能是强制类型转换
// if (a == 1)
// {
// // boundPoints.push_back(cloud->points[i]);
// (*boundPoints).push_back(cloud->points[i]);
// countBoundaries++;
// }
// else
// noBoundPoints.push_back(cloud->points[i]);
//
// }
// std::cout << "boudary size is:" << countBoundaries << std::endl;
//
// pcl::io::savePCDFileBinary("F://cout-saved//boudary.pcd", *boundPoints);
// pcl::io::savePCDFileBinary("F://cout-saved//NoBoundpoints.pcd", noBoundPoints);
// pcl::visualization::CloudViewer viewer("test");
// viewer.showCloud(boundPoints);
// while (!viewer.wasStopped())
// {
// }
// return 0;
//}
不知道什么时间收集的code相关推荐
- 花了2周时间收集汇总的大厂面经,节后准备跳槽的看过来!
今年过年比较早,那跳槽旺季也要提前啦.准备跳槽的小伙伴是不是已经早早开始刷算法八股文. 刷题是一方面,提前了解大厂的面试流程也很重要. 这里有一份新鲜出炉的2021全年大厂Java后端面经汇总,请你查 ...
- 期待我的不知道什么时间能到来的宝宝
呵呵 最近似乎迷上了想做妈妈的心态 看到可爱的宝宝我都幻想这那是我的宝宝 爱毕他们的一举一动一颦一笑 很有种冲动把他们抱在自己的怀抱里亲亲他们 我想 我的母爱已经到来了 那么 我的宝宝 我等你的到来哦 ...
- 你太菜了,竟然不知道Code Review...
点击上方"方志朋",选择"设为星标" 回复"666"获取新整理的面试资料 作者:宝玉 来源:http://1t.click/aA4h 我 ...
- 第四十八期:你太菜了,竟然不知道Code Review?
我一直认为Code Review(代码审查)是软件开发中的优秀实践之一,可以有效提高整体代码质量,及时发现代码中可能存在的问题. 作者:宝玉 我一直认为Code Review(代码审查)是软件开发中的 ...
- 作为CTO,我为什么必须要求代码进行Code Review!
来源:宝玉 链接:https://cnblogs.com/dotey/p/11216430.html 我一直认为Code Review(代码审查)是软件开发中的最佳实践之一,可以有效提高整体代码质量, ...
- Code Review最佳实践
我一直认为Code Review(代码审查)是软件开发中的最佳实践之一,可以有效提高整体代码质量,及时发现代码中可能存在的问题.包括像Google.微软这些公司,Code Review都是基本要求,代 ...
- 敏捷开发中的Code Review
敏捷开发中的Code Review 一些敏捷团队在实施敏捷开发中忙于编码.忙于Unit Test.忙于沟通.忙于Build等,虽然也有编码审核阶段,但大都浮于表面,流于形式,效果不佳.本文结合实践,介 ...
- 从Script到Code Blocks、Code Behind到MVC、MVP、MVVM
刚过去的周五(3-14)例行地主持了技术会议,主题正好是<UI层的设计模式--从Script.Code Behind到MVC.MVP.MVVM>,是前一天晚上才定的,中午花了半小时准备了下 ...
- 时间计算题100道_2019四校及分校自招开放日情况汇总(含时间安排、考试内容难度、到场人数等)...
点击上方"上海初升高",选择"星标公众号" 回复"加群"就能加入上万家长信赖的升学群 受到疫情的影响,今年各市重点的自招开放日报名迟迟没有提 ...
最新文章
- 不敢相信,居然用Java写了个“天天酷跑”!
- 禁毒学、油画、乌尔都语……字节跳动程序员的专业有多奇特丨技术同学大数据报告...
- 移动端目标识别(1)——使用TensorFlow Lite将tensorflow模型部署到移动端(ssd)之TensorFlow Lite简介...
- Prometheus 由于时间不同步导致数据不显示
- linux中配置jmeter环境变量,linux java 和jmeter 环境变量配置文件笔记(原)
- 音视频技术开发周刊 54期
- 初一模拟赛总结(3.16)
- C或C 如何通过程序执行shell命令并获取命令执行结果?
- 第三范式的作用_钟启泉:教学范式的转型,让一线教师面临三大挑战 | 头条
- RSF 分布式服务框架-传输协议层设计
- spring boot 教程(五)使用JdbcTemplate访问数据库
- Protel99SE覆铜笔记
- ckeditor 3.6一直提示“例外被抛出且未被接住”的问题的解决方法
- 手机工商银行显示服务器安装不了,工行网银助手无法安装怎么办?
- 解决MacBook无法读写移动硬盘的问题
- Matlab数学建模学习报告(一)
- web开发中添加分享按钮
- Carsim 学习心得-粗略翻译1
- 从PD充电器取9V/12V给产品供电快充,PD取电芯片概述
- 金蝶生成凭证模板_【干货】金蝶云ERP教你凭证模版的引入引出