将三维点云投影到XOZ面上
生活随笔
收集整理的這篇文章主要介紹了
将三维点云投影到XOZ面上
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??
如圖左邊是原始的三維點云pcd格式,右邊是投影到XOZ面上的數據,Y為0.
#include <iostream>
#include <pcl/filters/project_inliers.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/filters/statistical_outlier_removal.h>
#include <pcl/features/normal_3d.h>
#include <pcl/segmentation/extract_clusters.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/ModelCoefficients.h>
#include<cstdlib>
#include <windows.h>
#include <pcl/console/parse.h>
#include <pcl/console/print.h>
#include <pcl/correspondence.h>
#include <boost/filesystem.hpp>using namespace pcl;
typedef PointXYZ PoinT;
int *rand_rgb()
{//隨機產生顏色int *rgb = new int[3];rgb[0] = rand() % 255;rgb[1] = rand() % 255;rgb[2] = rand() % 255;return rgb;
}int
main(int argc, char** argv)
{pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_projected(new pcl::PointCloud<pcl::PointXYZ>);//點云的讀取*********************************************************if (io::loadPCDFile("F://coutsaved//test//boxes//pcd//11Cloud.pcd", *cloud) == -1){PCL_ERROR("read false");return 0;}// Create a set of planar coefficients with X=Y=0,Z=1//In this case, we use a plane model, with ax+by+cz+d=0, where a=b=d=0, and c=1, or said differently, the X-Y plane.pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients());coefficients->values.resize(4);coefficients->values[0] = 0;coefficients->values[1] = 1.0;coefficients->values[2] = 0;coefficients->values[3] = 0;visualization::PCLVisualizer::Ptr viewer1(new visualization::PCLVisualizer("Remove-Y"));// Create the filtering objectpcl::ProjectInliers<pcl::PointXYZ> proj;proj.setModelType(pcl::SACMODEL_PLANE);proj.setInputCloud(cloud);proj.setModelCoefficients(coefficients);proj.filter(*cloud_projected);io::savePCDFileASCII("F://coutsaved//test//boxes//plane//removey.pcd", *cloud_projected);//保存投影到XOZ面上的點云int *rgb = rand_rgb(); //隨機生成0-255的顏色值visualization::PointCloudColorHandlerCustom<PoinT>rgb1(cloud_projected, rgb[0], rgb[1], rgb[2]);delete[]rgb;viewer1->addPointCloud(cloud_projected, rgb1, "F://coutsaved//test//boxes//plane//removey.pcd");system("pause");return (0);
}
?
總結
以上是生活随笔為你收集整理的将三维点云投影到XOZ面上的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Kdtree(K-dimension t
- 下一篇: VS2015 win64下配置Open