日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

PCL点云曲面重采样三种方法:上采样,下采样,均匀采样

發布時間:2025/3/21 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PCL点云曲面重采样三种方法:上采样,下采样,均匀采样 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

(1)下采樣? Downsampling

一般下采樣是通過構造一個三維體素柵格,然后在每個體素內用體素內的所有點的重心近似顯示體素中的其他點,這樣體素內所有點就用一個重心點來表示,進行下采樣的來達到濾波的效果,這樣就大大的減少了數據量,特別是在配準,曲面重建等工作之前作為預處理,可以很好的提高程序的運行速度,

#include <pcl/io/pcd_io.h> #include <pcl/filters/voxel_grid.h>int main(int argc, char** argv) {// 創建點云對象pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);pcl::PointCloud<pcl::PointXYZ>::Ptr filteredCloud(new pcl::PointCloud<pcl::PointXYZ>);// 讀取PCD文件if (pcl::io::loadPCDFile<pcl::PointXYZ>(argv[1], *cloud) != 0){return -1;}// 創建濾波對象pcl::VoxelGrid<pcl::PointXYZ> filter;filter.setInputCloud(cloud);// 設置體素柵格的大小為 1x1x1cmfilter.setLeafSize(0.01f, 0.01f, 0.01f);filter.filter(*filteredCloud); }

實驗結果(略)

(2)

均勻采樣:這個類基本上是相同的,但它輸出的點云索引是選擇的關鍵點在計算描述子的常見方式。

#include <pcl/io/pcd_io.h> #include <pcl/keypoints/uniform_sampling.h>int main(int argc, char** argv) {pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);pcl::PointCloud<pcl::PointXYZ>::Ptr filteredCloud(new pcl::PointCloud<pcl::PointXYZ>);if (pcl::io::loadPCDFile<pcl::PointXYZ>(argv[1], *cloud) != 0){return -1;}// Uniform sampling object.pcl::UniformSampling<pcl::PointXYZ> filter;filter.setInputCloud(cloud);filter.setRadiusSearch(0.01f);// We need an additional object to store the indices of surviving points.pcl::PointCloud<int> keypointIndices;filter.compute(keypointIndices);pcl::copyPointCloud(*cloud, keypointIndices.points, *filteredCloud); }

(3)增采樣 :增采樣是一種表面重建方法,當你有比你想象的要少的點云數據時,增采樣可以幫你恢復原有的表面(S),通過內插你目前擁有的點云數據,這是一個復雜的猜想假設的過程。所以構建的結果不會百分之一百準確,但有時它是一種可選擇的方案。所以,在你的點云云進行下采樣時,一定要保存一份原始數據!

#include <pcl/io/pcd_io.h> #include <pcl/surface/mls.h>int main(int argc,char** argv) { // 新建點云存儲對象 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); pcl::PointCloud<pcl::PointXYZ>::Ptr filteredCloud(new pcl::PointCloud<pcl::PointXYZ>);// 讀取文件if (pcl::io::loadPCDFile<pcl::PointXYZ>(argv[1], *cloud) != 0){return -1;}// 濾波對象pcl::MovingLeastSquares<pcl::PointXYZ, pcl::PointXYZ> filter;filter.setInputCloud(cloud);//建立搜索對象pcl::search::KdTree<pcl::PointXYZ>::Ptr kdtree;filter.setSearchMethod(kdtree);//設置搜索鄰域的半徑為3cmfilter.setSearchRadius(0.03);// Upsampling 采樣的方法有 DISTINCT_CLOUD, RANDOM_UNIFORM_DENSITYfilter.setUpsamplingMethod(pcl::MovingLeastSquares<pcl::PointXYZ, pcl::PointXYZ>::SAMPLE_LOCAL_PLANE);// 采樣的半徑是filter.setUpsamplingRadius(0.03);// 采樣步數的大小filter.setUpsamplingStepSize(0.02);filter.process(*filteredCloud); }

實驗的結果

原始圖像可視化:

?

(4)表面重建

深度傳感器的測量是不準確的,和由此產生的點云也是存在的測量誤差,比如離群點,孔等表面,可以用一個算法重建表面,遍歷所有的點云和插值數據,試圖重建原來的表面。比如增采樣,PCL使用MLS算法和類。執行這一步是很重要的,因為由此產生的點云的法線將更準確。

#include <pcl/io/pcd_io.h> #include <pcl/surface/mls.h> #include <pcl/visualization/pcl_visualizer.h> #include <pcl/visualization/cloud_viewer.h> #include <boost/thread/thread.hpp> int main(int argc, char** argv) {pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>); pcl::PointCloud<pcl::PointNormal>::Ptr smoothedCloud(new pcl::PointCloud<pcl::PointNormal>);if (pcl::io::loadPCDFile<pcl::PointXYZ>(argv[1], *cloud) != 0){return -1;}// Smoothing object (we choose what point types we want as input and output).pcl::MovingLeastSquares<pcl::PointXYZ, pcl::PointNormal> filter;filter.setInputCloud(cloud);// Use all neighbors in a radius of 3cm.filter.setSearchRadius(0.03);// If true, the surface and normal are approximated using a polynomial estimation// (if false, only a tangent one).filter.setPolynomialFit(true);// We can tell the algorithm to also compute smoothed normals (optional).filter.setComputeNormals(true);// kd-tree object for performing searches.pcl::search::KdTree<pcl::PointXYZ>::Ptr kdtree;filter.setSearchMethod(kdtree);filter.process(*smoothedCloud);boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer(new pcl::visualization::PCLVisualizer("smooth")); viewer->addPointCloud<pcl::PointNormal>(smoothedCloud,"smoothed");while(!viewer->wasStopped()){viewer->spinOnce(100); boost::this_thread::sleep(boost::posix_time::microseconds(1000000));} }

運行即可查看結果

?????????????????????????????????????????????????????????????? 原始圖像(加了顏色)

???????????????????????????????????????????? 增采樣平滑后(沒有顏色信息)

?

《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀

總結

以上是生活随笔為你收集整理的PCL点云曲面重采样三种方法:上采样,下采样,均匀采样的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。