PCL边界识别
来源:互联网 发布:python常用包 编辑:程序博客网 时间:2024/06/04 23:43
———————————–【转自:SimpleTriangle】————————————–
#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>(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>()); /* 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); // normEst.setRadiusSearch(2); //法向估计的半径 normEst.setKSearch(9); //法向估计的点数 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(20); //一般这里的数值越高,最终边界识别的精度越好 // est.setRadiusSearch(everagedistance); //搜索半径 est.compute (boundaries); // pcl::PointCloud<pcl::PointXYZ> boundPoints; 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("boudary.pcd",boundPoints); pcl::io::savePCDFileASCII("boudary.pcd", *boundPoints); pcl::io::savePCDFileASCII("NoBoundpoints.pcd",noBoundPoints); pcl::visualization::CloudViewer viewer ("test"); viewer.showCloud(boundPoints); while (!viewer.wasStopped()) { } return 0;}
阅读全文
0 0
- PCL边界识别
- PCL中的点云模型边界保留
- 帧边界识别简介
- h264帧边界识别
- H264 帧边界识别简介
- H264 帧边界识别简介
- H264 帧边界识别简介
- H264 帧边界识别简介
- H264帧边界识别简介(转载)
- 图像边界识别梯度与热度关系
- 识别边界类/控制类/实体类
- pcl 基于对应分组的三维目标识别
- 边界
- Nao机器人基于颜色表的足球场地边界识别
- 边界,边界,还是边界
- 基于MFC 对话框的 PCL、VTK 、OPENCV岩体识别系统构建(1)
- 基于MFC 对话框的 PCL、VTK 、OPENCV岩体识别系统构建(2)
- PCL--pcl::copyPointCloud 使用方法
- Android 实战开发 Git配置
- 自动驻车和电子手刹傻傻分不清怎么办
- 怎么样给小孩取名字?准爸妈为孩子起名字的另类姿势
- BZOJ 2120 带修改莫队
- 复杂业务逻辑下的合理遍历
- PCL边界识别
- JS中的非空判断 undefined,null, NaN的区别
- Androidstudio中修改默认布局
- 第四章 字符串
- C语言递归穷举n位m进制数字(回溯)
- InstallShield打包程序时设为extract from exe
- Python爬虫入门:Urllib库的基本使用
- jieba中文处理
- Eclipse中将输出信息显示到控制台同时存到指定日志中