PCL区域增长分割_viewer->setshaperenderingproperties-程序员宅基地

技术标签: C/C++  PointCloud  pcl  点云分割  

代码

 

#include <iostream>
#include <vector>
#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/search/search.h>
#include <pcl/search/kdtree.h>
#include <pcl/features/normal_3d.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/filters/passthrough.h>
#include <pcl/segmentation/region_growing.h>
#include <pcl/console/print.h>
#include <pcl/console/parse.h>
#include <pcl/console/time.h>

#include <stdio.h>


using namespace pcl::console;
int
main (int argc, char** argv)
{

	if(argc<2)
	{
		std::cout<<".exe xx.pcd -kn 50 -bc 0 -fc 10.0 -nc 0 -st 30 -ct 0.05"<<endl;

		return 0;
	}//����������С��1���������ʾ
	time_t start,end,diff[5],option;//���弸��ʱ�̣����ں����������ÿһ�����ѵ�ʱ��
	start = time(0); 
	int KN_normal=50; //����Ĭ���������
	bool Bool_Cuting=false;//����Ĭ���������
	float far_cuting=10,near_cuting=0,SmoothnessThreshold=5.0,CurvatureThreshold=0.05;//����Ĭ���������
	parse_argument (argc, argv, "-kn", KN_normal);//�������ڷ��������Ƶ�k������Ŀ
	parse_argument (argc, argv, "-bc", Bool_Cuting);//�����Ƿ���Ҫֱͨ�˲�
	parse_argument (argc, argv, "-fc", far_cuting);//ֱͨ�˲������ֵ
	parse_argument (argc, argv, "-nc", near_cuting);//ֱͨ�˲�����Сֵ
	parse_argument (argc, argv, "-st", SmoothnessThreshold);//ƽ����ֵ
	parse_argument (argc, argv, "-ct", CurvatureThreshold);//������ֵ
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
	if ( pcl::io::loadPCDFile <pcl::PointXYZ> (argv[1], *cloud) == -1)
	{
		std::cout << "Cloud reading failed." << std::endl;
		return (-1);
	}// ���������������
	end = time(0); 
	diff[0] = difftime (end, start); 
	PCL_INFO ("\tLoading pcd file takes(seconds): %d\n", diff[0]);
	//Noraml estimation step(1 parameter)
	//����һ��tree����
	pcl::search::Search<pcl::PointXYZ>::Ptr tree = boost::shared_ptr<pcl::search::Search<pcl::PointXYZ> > (new pcl::search::KdTree<pcl::PointXYZ>);//����һ��ָ��kd����������Ĺ���ָ��
	pcl::PointCloud <pcl::Normal>::Ptr normals (new pcl::PointCloud <pcl::Normal>);
	pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> normal_estimator;//�������߹��ƶ���
	normal_estimator.setSearchMethod (tree);//������������
	normal_estimator.setInputCloud (cloud);//���÷��߹��ƶ�������㼯
	normal_estimator.setKSearch (KN_normal);// �������ڷ��������Ƶ�k������Ŀ
	normal_estimator.compute (*normals);//���㲢���������
	end = time(0); 
	diff[1] = difftime (end, start)-diff[0]; 
	PCL_INFO ("\tEstimating normal takes(seconds): %d\n", diff[1]);//������߹�����һ�����˶��ʱ��
	//optional step: cutting the part are far from the orignal point in Z direction.2 parameters
	pcl::IndicesPtr indices (new std::vector <int>);//����һ������
	if(Bool_Cuting)//�ж��Ƿ���Ҫֱͨ�˲�
	{

		pcl::PassThrough<pcl::PointXYZ> pass;//����ֱͨ�˲�������
		pass.setInputCloud (cloud);//�����������
		pass.setFilterFieldName ("z");//����ָ�����˵�ά��
		pass.setFilterLimits (near_cuting, far_cuting);//����ָ��γ�ȹ��˵ķ�Χ
		pass.filter (*indices);//ִ���˲��������˲����������������
	}


	// ���������㷨��5������
	pcl::RegionGrowing<pcl::PointXYZ, pcl::Normal> reg;//�������������ָ����
	reg.setMinClusterSize (100);//����һ��������Ҫ����С����
	reg.setMaxClusterSize (5000);//����һ��������Ҫ��������
	reg.setSearchMethod (tree);//������������
	reg.setNumberOfNeighbours (10);//然后设置参考的邻域点数,也就是看看周边的多少个点来决定这是一个平面(这个参数至关重要,决定了你的容错率,如果设置的很大,那么从全局角度看某一个点稍微有点歪也可以接受,如果设置的很小则通常检测到的平面都会很小)
	reg.setInputCloud (cloud);//�����������
	if(Bool_Cuting)reg.setIndices (indices);//ͨ������������ã�ȷ���Ƿ������������.�����Ҫֱͨ�˲���������������Ƶ�����
	reg.setInputNormals (normals);//����������Ƶķ�����
	reg.setSmoothnessThreshold (20 / 180.0 * M_PI);//平滑阈值,法向量的角度差
	reg.setCurvatureThreshold (0.05);//曲率阈值,代表平坦的程度

	std::vector <pcl::PointIndices> clusters;//����ÿһ�־��࣬ÿһ�־������滹�о���ĵ�
	reg.extract (clusters);//��ȡ����Ľ�����ָ��������ڵ��������������С�
	end = time(0); 
	diff[2] = difftime (end, start)-diff[0]-diff[1]; //���������ָ��㷨���ѵ�ʱ��
	PCL_INFO ("\tRegion growing takes(seconds): %d\n", diff[2]);

	std::cout << "Number of clusters is equal to " << clusters.size () << std::endl;//�����������������
	std::cout << "First cluster has " << clusters[0].indices.size () << " points." << endl;//�����һ�������е������




	//保存聚类的点云-------------------------------------------------------------------
    int j = 0;
    for (std::vector<pcl::PointIndices>::const_iterator it = clusters.begin (); it != clusters.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 << "cloud_cluster_" << j << ".pcd";
        pcl::io::savePCDFileASCII(ss.str(),*cloud_cluster);
        cout<<ss.str()<<"Saved"<<endl;
        j++;
    }


/***
 * But this function doesn't guarantee that different segments will have different
        * color(it all depends on RNG). Points that were not listed in the indices array will have red color.
 */
	pcl::PointCloud <pcl::PointXYZRGB>::Ptr colored_cloud = reg.getColoredCloud ();
	//保存附加颜色的点云
//	pcl::io::savePCDFileASCII("colored_pointCloud.pcd",*colored_cloud);
	pcl::visualization::PCLVisualizer viewer ("区域增长分割");
//    viewer.setShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE,8,"coloredCloud");

    viewer.addPointCloud(colored_cloud);
//	viewer.setShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE,8);
	while (!viewer.wasStopped ())
	{
	    viewer.spinOnce();
	}

	return (0);
}

可视化

 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/suyunzzz/article/details/103646594

智能推荐

MYSQL数据库四种索引类型介绍_mysql可以使用那些列作为数据索引-程序员宅基地

文章浏览阅读8.4k次,点赞17次,收藏25次。MYSQL数据库四种索引类型主键索引: 主键是一种唯一性索引,但它必须指定为PRIMARY KEY,每个表只能有一个主键。唯一索引: 索引列的所有值都只能出现一次,即必须唯一,值可以为空。普通索引 : 基本的索引类型,值可以为空,没有唯一性的限制。全文索引: 全文索引的索引类型为FULLTEXT。全..._mysql可以使用那些列作为数据索引

c#中用循环语句输出九九乘法表_c# 通过for循环输出10 20 30-程序员宅基地

文章浏览阅读5.2k次,点赞3次,收藏5次。 一些基础的逻辑运算,自己也是初学者,记录一下,全是自己的一些见解,大神请轻喷输出结果:代码:public void ChengFaBiao(){ for (int a = 1;a&lt;=9;a++){ for (int b = 1; b &lt;= a; b++) { Console.Write (b + "*" + a + "=" + a * b+" "); ..._c# 通过for循环输出10 20 30

AGPBI: {"kind":"error","text":"Cannot fit requested classes in a single dex file (# methods: 67300 >-程序员宅基地

文章浏览阅读2.8k次。错误信息 AGPBI: {"kind":"error","text":"Cannot fit requested classes in a single dex file (# methods: 67300 > 65536)","sources":[{}],"tool":"D8"}com.android.builder.dexing.DexArchiveMergerExce..._agpbi: {"kind":"error","text":"cannot fit requested classes in a single dex

python之windrose风向玫瑰图的用法_windroseaxes.from_ax-程序员宅基地

文章浏览阅读2w次,点赞4次,收藏47次。1.安装A package is available and can be downloaded from PyPi and installed using:$ pip install windroseInstall latest development version$ pip install git+https://github.com/python-windrose/wi..._windroseaxes.from_ax

pxe linux 配置文件,(六)PXE技术篇--pxelinux 的配置文件-程序员宅基地

文章浏览阅读1k次。pxe 启动引导器pxelinux.0 在 syslinux 包中, 把它拷贝到 /var/lib/tftpboot/ 下, 客户机会从此目录读取该文件安装yum -y install syslinux复制文件cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot我们告诉客户端使用 vmlinuz 作为内核, 并且使用 initrd.img 作为初..._pxelinux.0文件在什么地方

图解:深度优先搜索与广度优先搜索及其六大应用_请叙述广度优先搜索和深度优先搜索的特点和使用场合-程序员宅基地

文章浏览阅读5.9k次,点赞13次,收藏46次。图算法第二篇 深度优先搜索与广度优先搜索及其应用约定:本文所有涉及的图均为无向图,有向图会在之后的文章涉及1.图的存储方式我们首先来回顾一下图的存储方式:邻接矩阵和邻接表。为了实现更好的性能,我们在实际应用中一般使用邻接表的方式来表示图。具体的实现代码为:package Graph;import java.util.LinkedList;public class Graph{ private final int V;//顶点数目 private int E;/.._请叙述广度优先搜索和深度优先搜索的特点和使用场合

随便推点

树莓派(3B)刷OpenWrt变路由_树莓派3b openwrt-程序员宅基地

文章浏览阅读2k次,点赞5次,收藏10次。树莓派(3B)刷OpenWrt变路由由于去年使用树莓派(3B+)进行此项目未成功,今年因为做别的项目,刚好换成了树莓派(3B),顺便就尝试着完成去年未完成的项目,最终成功,顺利将树莓派(3B)通过刷OpenWrt将其变身路由。在此,非常感谢带我入门的学长,本次项目是在学长研究的基础上进行的,真正的成功属于他们,我只是一个搬运者与借鉴者。一、格式化SD卡使用“SDFormatter.exe”工具格式化SD卡;二、烧录OpenWrt镜像打开“Win32DiskImager.exe”工具,找到完成格式_树莓派3b openwrt

进程环境相关(APUE)_linux 进程 文件 apue-程序员宅基地

文章浏览阅读90次。就是一个main程序的运行开始到结束的一些介绍,运行环境的一些,比较简单的一章,里面那个setjmp和longjmp函数那里有点难懂,记得后面信号那里还出现了。mian函数背后进程(main函数)的开始进程的终止的方式(8种(其中5种正常))三个正常终止进程的函数:exit、_exit和_Exit,三者有什么不同,参数代表什么(终止状态)什么情况下终止状态是未定义的,什么情况下终止状态..._linux 进程 文件 apue

《Linux从0到99》七 进程地址空间_99在内存中的地址-程序员宅基地

文章浏览阅读108次。地址空间1. 什么是地址空间?2. 虚拟地址空间出现的原因3. 地址空间的工作方式4. 地址空间的三种管理方式01 分页式内存管理(提高内存利用率)02 分段式内存管理(便于管理)03 段页式内存管理(既提高了内存利用率,又便于内存管理)1. 什么是地址空间?地址空间(address space) 表示任何一个计算机实体所占用的内存大小。比如外设、文件、服务器或者一个网络计算机。地址空间包括物理空间以及虚拟空间。物理地址 (physical address): 放在寻址总线上的地址。放在寻址总线上_99在内存中的地址

php mysql 排名算法_PHP实现四种基础排序算法的运行时间比较(推荐)-程序员宅基地

文章浏览阅读120次。许多人都说算法是程序的核心,算法的好坏决定了程序的质量。作为一个初级phper,虽然很少接触到算法方面的东西。但是对于基本的排序算法还是应该掌握的,它是程序开发的必备工具。下面通过本文给大家介绍PHP实现四种基础排序算法的运行时间比较,一起看下吧。废话不多说了,直接给大家贴代码了。具体代码如下所示:/*** php四种基础排序算法的运行时间比较* @authors Jesse (jesse152@..._for($i=0;$i

YOLOV3代码详解_b, target_labels = target[:, :2].long().t()-程序员宅基地

文章浏览阅读7.5k次,点赞16次,收藏126次。代码分析:https://github.com/eriklindernoren/PyTorch-YOLOv3论文地址:https://pjreddie.com/media/files/papers/YOLOv3.pdf注:本次分析的代码是以上给出的网址,全部根据自己的理解写的,如有不足,还请指正。1、datasets.py因为所有模型都包括数据加载,模型载入,训练和测试等,所以先从数据的载..._b, target_labels = target[:, :2].long().t()

均衡技术matlab,无线通信均衡技术matlab仿真.doc-程序员宅基地

文章浏览阅读304次。无线通信均衡技术matlab仿真现给出迫零均衡(ZF)、最小均方误差均衡中的最小均方算法(LMS)的matlab程序,理解各程序,完成以下习题。将程序运行结果及各题目的解答写入word中:用matlab分别运行“main_zf.m”和“main_lms.m”(a)在程序中标注“注释”处加上注释(英文或中文)。(b)写出这两种算法实现的流程。(c)运行程序,会得到关于信号的一系列图形,包括信号序列图..._matlab信道均衡代码

推荐文章

热门文章

相关标签