最近在看PCL濾波配準(zhǔn)等操作,之前在自動(dòng)駕駛-激光雷達(dá)預(yù)處理/特征提取和提到了一些濾除點(diǎn)云等操作,但是最近作者發(fā)現(xiàn)里面還有一些配準(zhǔn)的方法還沒(méi)有提到,所以這里重新開(kāi)個(gè)章節(jié)來(lái)給大家列舉一些常用的濾波方式,方便大家查閱和使用
濾波&聚類
1.1 直通濾波器
void pass_through_filter(const pcl::PointCloud< pcl::PointXYZRGB >::Ptr &input_cloud) //直通濾波器 { std::cout < < "start pass_through_filter" < < std::endl; calc_sight_center(); //計(jì)算視點(diǎn)中心,視點(diǎn)中心為濾波器的輸入?yún)?shù) //
void ex_segmentor::calc_sight_center() // { // double roll, pitch, yaw; //
tf::Quaternion quat_tmp; // tf::quaternionMsgToTF(latest_camera_pos_.pose.pose.orientation, quat_tmp); // tf::Matrix3x3(quat_tmp).getRPY(roll, pitch, yaw); // centerX_ = latest_camera_pos_.pose.pose.position.x + gaze_length_ * cos(yaw); //
centerY_ = latest_camera_pos_.pose.pose.position.y + gaze_length_ * sin(yaw); //
centerZ_ = latest_camera_pos_.pose.pose.position.z - gaze_length_ * sin(pitch); // } //
build the condition pcl::ConditionAnd< pcl::PointXYZRGB >::Ptr range_limit(new pcl::ConditionAnd< pcl::PointXYZRGB >); //構(gòu)建范圍限制條件
range_limit- >addComparison(pcl::FieldComparison< pcl::PointXYZRGB >::ConstPtr(new pcl::FieldComparison< pcl::PointXYZRGB >("x", pcl::ComparisonOps::GT, centerX_ - 1.5))); // x坐標(biāo)大于視點(diǎn)中心x坐標(biāo)-1.5 range_limit- >addComparison(pcl::FieldComparison< pcl::PointXYZRGB >::ConstPtr(new pcl::FieldComparison< pcl::PointXYZRGB >("x", pcl::ComparisonOps::LT, centerX_ + 1.5))); // x坐標(biāo)小于視點(diǎn)中心x坐標(biāo)+1.5
range_limit- >addComparison(pcl::FieldComparison< pcl::PointXYZRGB >::ConstPtr(new pcl::FieldComparison< pcl::PointXYZRGB >("y", pcl::ComparisonOps::GT, centerY_ - 1.5))); // y坐標(biāo)大于視點(diǎn)中心y坐標(biāo)-1.5
range_limit- >addComparison(pcl::FieldComparison< pcl::PointXYZRGB >::ConstPtr(new pcl::FieldComparison< pcl::PointXYZRGB >("y", pcl::ComparisonOps::LT, centerY_ + 1.5))); // y坐標(biāo)小于視點(diǎn)中心y坐標(biāo)+1.5
range_limit- >addComparison(pcl::FieldComparison< pcl::PointXYZRGB >::ConstPtr(new pcl::FieldComparison< pcl::PointXYZRGB >("z", pcl::ComparisonOps::GT, centerZ_ - 1.5))); // z坐標(biāo)大于視點(diǎn)中心z坐標(biāo)-1.5
range_limit- >addComparison(pcl::FieldComparison< pcl::PointXYZRGB >::ConstPtr(new pcl::FieldComparison< pcl::PointXYZRGB >("z", pcl::ComparisonOps::LT, centerZ_ + 1.5))); // z坐標(biāo)小于視點(diǎn)中心z坐標(biāo)+1.5 //構(gòu)建濾波器
pcl::ConditionalRemoval< pcl::PointXYZRGB > condrem; //構(gòu)建濾波器
condrem.setCondition(range_limit); //設(shè)置濾波條件
condrem.setInputCloud(input_cloud); //設(shè)置輸入點(diǎn)云 //濾波操作
condrem.filter(*input_cloud); }
1.2 離群點(diǎn)濾波器
void statical_outlier_filter(const pcl::PointCloud<PointXYZRGB>::Ptr &input_cloud, int nr_k, double stddev_mult) //濾波器移除離群點(diǎn) { pcl::StatisticalOutlierRemoval<PointXYZRGB> sorfilter(true); //構(gòu)建濾波器 sorfilter.setInputCloud(input_cloud); sorfilter.setMeanK(nr_k); //設(shè)置在進(jìn)行統(tǒng)計(jì)時(shí)考慮的臨近點(diǎn)個(gè)數(shù) sorfilter.setStddevMulThresh(stddev_mult); //設(shè)置判斷是否為離群點(diǎn)的閥值,用來(lái)倍乘標(biāo)準(zhǔn)差,也就是上面的stddev_mult sorfilter.filter(*input_cloud); //濾波結(jié)果存儲(chǔ)到cloud_filtered }
1.3 體素化濾波器
void voxel_filter(const pcl::PointCloud< PointXYZRGB >::Ptr &input_cloud, float resolution) //體素化濾波器
{ pcl::VoxelGrid< PointXYZRGB > voxel_grid; //構(gòu)建體素化濾波器
voxel_grid.setInputCloud(input_cloud); //設(shè)置輸入點(diǎn)云
voxel_grid.setLeafSize(resolution, resolution, resolution); //設(shè)置體素的大小 voxel_grid.filter(*input_cloud); //濾波結(jié)果存儲(chǔ)到cloud_filtered }
1.4 平面點(diǎn)濾除
bool remove_plane(const pcl::PointCloud< PointXYZRGB >::Ptr &input_cloud, const Eigen::Vector3f &axis, double plane_thickness) //移除平面 { pcl::ModelCoefficients::Ptr
coefficients(new pcl::ModelCoefficients); //平面參數(shù)矩陣
pcl::PointIndices::Ptr inliers(new pcl::PointIndices); //平面內(nèi)點(diǎn)索引 // Create the
segmentation object pcl::SACSegmentation< pcl::PointXYZRGB > seg; //構(gòu)建分割對(duì)象
seg.setOptimizeCoefficients(true); //設(shè)置是否優(yōu)化系數(shù)
seg.setModelType(pcl::SACMODEL_PERPENDICULAR_PLANE); //設(shè)置模型類型為平面
seg.setMethodType(pcl::SAC_RANSAC); //設(shè)置分割方法為RANSAC
seg.setMaxIterations(500); //設(shè)置最大迭代次數(shù) seg.setAxis(axis); //設(shè)置分割軸 seg.setEpsAngle(0.25); //設(shè)置角度閾值
seg.setDistanceThreshold(plane_thickness); //設(shè)置距離閾值 0.025 0.018
seg.setInputCloud(input_cloud); //設(shè)置輸入點(diǎn)云 seg.segment(*inliers,
*coefficients); //分割平面 if (inliers- >indices.size() < 500) { //
ROS_INFO("plane size is not enough large to remove."); return false; }
pcl::ExtractIndices< pcl::PointXYZRGB > extract; extract.setInputCloud(input_cloud); //設(shè)置輸入點(diǎn)云 extract.setIndices(inliers); //設(shè)置索引,用來(lái)濾除 extract.setNegative(true); //設(shè)置是否濾除索引內(nèi)的點(diǎn) extract.filter(*input_cloud); return true; }
1.5 RGBD顏色特征聚類
void clustoring_with_color(pcl::PointCloud<pcl::PointXYZRGB>::Ptr &input_cloud, std::vector<pcl::PointCloud<PointXYZRGB>::Ptr> &clusters, int min_cluster_size, float distance_th, float color_th, float region_color_th, unsigned int num_nbr) //根據(jù)點(diǎn)云的顏色完成聚類 { std::vector<pcl::PointIndices> clusters_indices; //聚類索引 pcl::search::KdTree<pcl::PointXYZRGB>::Ptr kdtree(new pcl::search::KdTree<pcl::PointXYZRGB>); //構(gòu)建kd樹(shù) kdtree->setInputCloud(input_cloud); //設(shè)置輸入點(diǎn)云 // 基于顏色的區(qū)域生長(zhǎng)聚類對(duì)象
pcl::RegionGrowingRGB<pcl::PointXYZRGB> clustering; clustering.setInputCloud(input_cloud); clustering.setSearchMethod(kdtree); //設(shè)置搜索方法 // 這里,最小簇大小也會(huì)影響后處理步驟: 小于這個(gè)值的clusters_indices將與鄰點(diǎn)合并。
clustering.setMinClusterSize(min_cluster_size); //設(shè)置最小簇大小 // 設(shè)置距離閾值,以知道哪些點(diǎn)將被視為,鄰點(diǎn) clustering.setDistanceThreshold(distance_th); // 1 // 顏色閾值,用于比較兩個(gè)點(diǎn)的RGB顏色 clustering.setPointColorThreshold(color_th); // 9 6.5 25.0f 18.0f // 后處理步驟的區(qū)域顏色閾值:顏色在閾值內(nèi)的clusters_indices將合并為一個(gè)。
clustering.setRegionColorThreshold(region_color_th); // 2 //區(qū)域耦合時(shí)檢查的附近的數(shù)量。默認(rèn)為100, 在不影響結(jié)果的范圍內(nèi)適度設(shè)定小范圍。
clustering.setNumberOfRegionNeighbours(num_nbr); //設(shè)置近鄰數(shù)量 //
clustering.setSmoothModeFlag(true); // clustering.setSmoothnessThreshold(0.95);
clustering.extract(clusters_indices); //提取聚類索引 for (std::vector<pcl::PointIndices>::const_iterator i = clusters_indices.begin(); i !=
clusters_indices.end(); ++i)//遍歷聚類索引 {
pcl::PointCloud<pcl::PointXYZRGB>::Ptr cluster(new
pcl::PointCloud<pcl::PointXYZRGB>); //構(gòu)建聚類點(diǎn)云 for
(std::vector<int>::const_iterator pit = i->indices.begin(); pit != i->indices.end(); ++pit) //遍歷聚類索引中的點(diǎn)索引 { cluster->points.push_back(input_cloud->points[*pit]); //將點(diǎn)添加到聚類點(diǎn)云 } cluster->width = cluster->points.size(); cluster->height = 1; cluster->is_dense = true; clusters.push_back(cluster); //將聚類點(diǎn)云添加到聚類點(diǎn)云集合中 } }
-
plc
+關(guān)注
關(guān)注
5004文章
13048瀏覽量
460881 -
濾波
+關(guān)注
關(guān)注
10文章
659瀏覽量
56541 -
點(diǎn)云
+關(guān)注
關(guān)注
0文章
58瀏覽量
3773
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論