obj物体模型生成PCL点云数据及PCL在ubuntu16.04下的安装

obj物体模型生成点云数据

#include <iostream>
#include <vector>
#include <ctime>
//---------------------------------------------
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/io/pcd_io.h>
#include <pcl/io/vtk_lib_io.h> //obj读取头文件
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/features/normal_3d.h>
//-法向显示错误:no override found for vtkActor--
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL);
//outlier
#include <pcl/filters/statistical_outlier_removal.h>

using namespace std;

int main() {
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
	pcl::PointCloud<pcl::PointXYZ>::Ptr bottom(new pcl::PointCloud<pcl::PointXYZ>);

	//-------------------------------读取点云文件---------------------------------------------------
	pcl::PolygonMesh mesh;
	if (pcl::io::loadPolygonFile("/home/mi/3rd_package/ch13/pcl_obj_test/bunny_low_resolution.obj", mesh) == -1)
	{
		cout << "COULD NOT READ FILE mid.pcl \n";
		system("pause");
		return (-1);
	}
	pcl::fromPCLPointCloud2(mesh.cloud, *cloud);

	cout << "points sieze is:" << cloud->size() << endl;
	
	//outlier
	pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>);
	pcl::StatisticalOutlierRemoval<pcl::PointXYZ> sor;
	sor.setInputCloud(cloud);
	sor.setMeanK(200);   //设置在进行统计时考虑查询点邻近点数
	sor.setStddevMulThresh(1.0);   //设置判断是否为离群点的阈值,如果一个点的距离超出平均距离一个标准差以上,则该点被标记为离群点,并将被移除。
	sor.filter(*cloud_filtered);
	//---------------------------------显示---------------------------------------------------------------------
	boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("3D viewer"));
	
	int v1(0);
	viewer->createViewPort(0.0, 0.0, 0.5, 1.0, v1);//xmin, ymin, xmax, ymax,取值范围0-1
	viewer->setBackgroundColor(0, 0, 0, v1);
	pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> green0(cloud, 0, 225, 0);
	viewer->addPointCloud(cloud, green0, "cloud", v1);

	int v2(0);
	viewer->createViewPort(0.5, 0.0, 1.0, 1.0, v2);
	viewer->setBackgroundColor(0.3, 0.3, 0.3, v2);
	pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> green1(cloud_filtered, 0, 225, 0);
	viewer->addPointCloud(cloud_filtered, green1, "cloud_filtered", v2);
	
	while (!viewer->wasStopped()) {
		viewer->spinOnce(100);
	}
	system("pause");
	return 0;
}

效果如下

生成了一只兔子的点云:

PCL安装过程参考:

https://blog.csdn.net/qq_36728314/article/details/89487719

过程中如果发现

/usr/include/pcl**/pcl/

下没有visualization文件夹

则所名没有安装vtk

  1. (在此如果要实现可视化需要跟新vtk版本,可以使用sudo apt-get install libvtk + Tab 补全查找自己需要的版本。

  2. 我使用的是sudo apt-get install libvtk6.2 libvtk6.2-qt libvtk6-dev)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值