資源簡介
利用PCL庫,通過濾波,分割,求長寬高,計算物體的體積,涉及到點云獲取、濾波、分割、配準(zhǔn)、檢索、特征提取、識別、追蹤、曲面重建、可視化等。

代碼片段和文件信息
#include?
#include?
#include??????????//OpenNI采集頭文件
#include?
#include?.
#include?
#include?
#include?????????????????????//直通濾波器頭文件
#include??????????????????????//體素濾波器頭文件
#include?????//統(tǒng)計濾波頭文件
#include?????????????????//索引提取濾波器頭文件
#include?????????????????//映射相關(guān)頭文件
#include???//基于采樣一致性分割的類的頭文件
#include???????????//采樣一致性模型相關(guān)類頭文件
#include???//隨機(jī)參數(shù)估計方法頭文件
#include????//模型定義頭文件
#include????????????//提取凸(凹)多邊形的頭文件.
#include?
#include?“opencv2/highgui/highgui.hpp“
#include?“opencv2/imgproc/imgproc.hpp“
using?namespace?std;
using?namespace?cv;
class?VolumDetectViewer
{
public:
boost::mutex?cloud_mutex;
pcl::visualization::PCLVisualizer?viewer;
//?直通濾波器對象
pcl::PassThrough?XpassFilter;
pcl::PassThrough?YpassFilter;
//?下采樣?VoxelGrid?濾波對象
pcl::VoxelGrid?VoxlFilter;
//?統(tǒng)計濾波器
pcl::StatisticalOutlierRemoval?statisFilter;
//?分割對象
pcl::SACSegmentation?segPlane;
//?提取索引濾波器
pcl::ExtractIndices?extractPlane;
//?點云投影濾波對象
pcl::ProjectInliers?projec;
VolumDetectViewer():viewer(“PCLVIEW“)
{
//?1.?初始化?new?viewer
//pcl::visualization::PCLVisualizer?viewer(“PCLVIEW“);
viewer.setBackgroundColor(0?0?0);
viewer.addCoordinateSystem(0.6);
viewer.initCameraParameters();
viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE?1?“cloud“);
//viewer.setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_OPACITY?0.15?“cloud“);
//?2.?直通濾波設(shè)置
//?濾波字段設(shè)為x軸方向.
XpassFilter.setFilterFieldName(“x“);
//?設(shè)定可接受范圍,將不在范圍內(nèi)的點過濾掉或者保留(由setFilterLimitsNegative決定).
XpassFilter.setFilterLimits(-0.25?0.05);??//?TODO:?X方向裁剪閾值需要調(diào)試?實際是0.44m.
//?濾波字段設(shè)為y軸方向.
YpassFilter.setFilterFieldName(“y“);
//?設(shè)定可接受范圍,將不在范圍內(nèi)的點過濾掉或者保留(由setFilterLimitsNegative決定).
YpassFilter.setFilterLimits(-0.25?0.18);??//?TODO:?Y方向裁剪閾值需要調(diào)試?實際是0.69m.
//?3.?體素濾波設(shè)置
//?設(shè)置體素濾波時創(chuàng)建的體素體積為0.5*0.5*0.5cm的立方體
VoxlFilter.setLeafSize(0.005f?0.005f?0.005f);
//?4.?統(tǒng)計濾波初始設(shè)置
statisFilter.setMeanK(50);??//?對每個點分析的臨近點個數(shù)設(shè)為50
statisFilter.setStddevMulThresh(1.0);???//?將標(biāo)準(zhǔn)差倍數(shù)設(shè)為1,意味著一個點的距離超出平均距離1個標(biāo)準(zhǔn)差以上,就會被標(biāo)記為離群點,并被移除。
//?5.?設(shè)置分割對象
//?可選:設(shè)置模型系數(shù)需要優(yōu)化
segPlane.setOptimizeCoefficients(true);
//?必選:設(shè)置分割的模型類型、所用的隨機(jī)參數(shù)估計方法、距離閾值、迭代次數(shù)上限
segPlane.setModelType(pcl::SACMODEL_PLANE);
segPlane.setMethodType(pcl::SAC_RANSAC);
segPlane.setDistanceThreshold(0.01);????//?TODO:?距離閾值需要調(diào)試
segPlane.setMaxIterations(1000);
//?6.?設(shè)置投影模型為SACMO
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2020-05-06?08:37??imgRecord\
?????文件?????5054181??2018-06-11?20:28??imgRecord\GIF.gif
?????文件??????330706??2018-06-11?20:28??imgRecord\originCloud.png
?????文件??????239551??2018-06-11?20:28??imgRecord\passThrough.png
?????文件??????160249??2018-06-11?20:28??imgRecord\PlaneSeg.png
?????文件??????145220??2018-06-11?20:28??imgRecord\statisFiltered.png
?????文件??????135432??2018-06-11?20:28??imgRecord\voxelFiltered.png
?????目錄???????????0??2020-05-06?08:04??source\
?????文件?????????411??2020-05-06?08:04??source\CMakeLists.txt
?????文件???????12822??2020-05-06?08:01??source\volDetectVisualizer.cpp
評論
共有 條評論