当前位置:网站首页>Extract a subset from a point cloud
Extract a subset from a point cloud
2022-07-21 21:01:00 【Amelie_ eleven】
6.2.5 Extract a subset from a point cloud
Code : Example 5 in Chapter 6 of the book
Modify two codes :
//sensor_msgs::PointCloud2::Ptr cloud_blob(new sensor_msgs::PointCloud2), cloud_filtered_blob(new sensor_msgs::PointCloud2);
// The above is the old way , To be changed to
pcl::PCLPointCloud2::Ptr cloud_blob(new pcl::PCLPointCloud2), cloud_filtered_blob(new pcl::PCLPointCloud2);
//pcl::fromROSMsg(*cloud_filtered_blob, *cloud_filtered);
// Change it to :
pcl::fromPCLPointCloud2(*cloud_filtered_blob, *cloud_filtered);
The whole code after modification :
#include <iostream>
#include <pcl/ModelCoefficients.h>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/sample_consensus/method_types.h>
#include <pcl/sample_consensus/model_types.h>
#include <pcl/segmentation/sac_segmentation.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/filters/extract_indices.h>
int
main(int argc, char** argv)
{
//sensor_msgs::PointCloud2::Ptr cloud_blob(new sensor_msgs::PointCloud2), cloud_filtered_blob(new sensor_msgs::PointCloud2);
pcl::PCLPointCloud2::Ptr cloud_blob(new pcl::PCLPointCloud2), cloud_filtered_blob(new pcl::PCLPointCloud2);
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud_filtered(new pcl::PointCloud<pcl::PointXYZ>), cloud_p(new pcl::PointCloud<pcl::PointXYZ>), cloud_f(new pcl::PointCloud<pcl::PointXYZ>);
// Fill in point cloud data
pcl::PCDReader reader;
reader.read("C:\\Users\\oh_clm\\Desktop\\ Point cloud Library PCL From entry to mastery \\ Chapter six \\5 extract_indices\\source\\table_scene_lms400.pcd", *cloud_blob);
std::cerr << "PointCloud before filtering: " << cloud_blob->width * cloud_blob->height << " data points." << std::endl;
// Create filter object : The leaf size used is 1cm Under sampling
pcl::VoxelGrid<pcl::PCLPointCloud2> sor;// Sample objects under the voxel grid
sor.setInputCloud(cloud_blob);// Set the down sampling of the original point cloud data
sor.setLeafSize(0.01f, 0.01f, 0.01f);// Set the speed-up size of sampling
sor.filter(*cloud_filtered_blob);// Execute sampling to save data
// Convert to template point cloud
//pcl::fromROSMsg(*cloud_filtered_blob, *cloud_filtered);
pcl::fromPCLPointCloud2(*cloud_filtered_blob, *cloud_filtered);
std::cerr << "PointCloud after filtering: " << cloud_filtered->width * cloud_filtered->height << " data points." << std::endl;
// Save the down sampled data to disk
pcl::PCDWriter writer;
writer.write<pcl::PointXYZ>("C:\\Users\\oh_clm\\Desktop\\ Point cloud Library PCL From entry to mastery \\ Chapter six \\5 extract_indices\\source\\table_scene_lms400_downsampled.pcd", *cloud_filtered, false);
/* Handle parametric segmentation */
pcl::ModelCoefficients::Ptr coefficients(new pcl::ModelCoefficients());
pcl::PointIndices::Ptr inliers(new pcl::PointIndices());
// Create split objects
pcl::SACSegmentation<pcl::PointXYZ> seg;
// Optional
seg.setOptimizeCoefficients(true);// Set to optimize the estimated model parameters
// Mandatory
seg.setModelType(pcl::SACMODEL_PLANE);// Set the split model category
seg.setMethodType(pcl::SAC_RANSAC);// Set which random parameter estimation method to use
seg.setMaxIterations(1000);// Set the maximum number of iterations
seg.setDistanceThreshold(0.01);// Determine whether it is the distance threshold of the inner point of the model
// Create filter object
pcl::ExtractIndices<pcl::PointXYZ> extract;
int i = 0, nr_points = (int)cloud_filtered->points.size();
// When still 30% Original point cloud data
while (cloud_filtered->points.size() > 0.3 * nr_points)
{
// Divide the largest plane component from the remaining point cloud
seg.setInputCloud(cloud_filtered);
seg.segment(*inliers, *coefficients);
if (inliers->indices.size() == 0)
{
std::cerr << "Could not estimate a planar model for the given dataset." << std::endl;
break;
}
// Separate the inner layer
extract.setInputCloud(cloud_filtered);// Set the input point cloud
extract.setIndices(inliers);// The internal points after segmentation are the point sets to be extracted
extract.setNegative(false);// Extract interior points Not the outer point
extract.filter(*cloud_p);// Extract the output and store it in cloud_p
std::cerr << "PointCloud representing the planar component: " << cloud_p->width * cloud_p->height << " data points." << std::endl;
std::stringstream ss;
ss << "table_scene_lms400_plane_" << i << ".pcd";
writer.write<pcl::PointXYZ>(ss.str(), *cloud_p, false);
// Create filter object
extract.setNegative(true);
extract.filter(*cloud_f);
cloud_filtered.swap(cloud_f);
i++;
}
return (0);
}
Running results :
The original point cloud :
Point cloud after down sampling
Split point cloud
边栏推荐
- Nodejs reads and parses the dom of XML
- 文件操作上(C语言)
- 加快无人机智能巡检规模化应用,福建电力输电运检智能化建设提速
- [vulnerability recurrence] cve-2022-22954 VMware workspace one access vulnerability analysis
- Boundary layer integral equation and Marangoni effect
- Openfoam programming: combination of VOF method and porous media model
- php三行代码写测试接口
- Redis与memcached有何不同
- Attack and defense World Web Zone difficulty level: 3 (ics-05, MFW, easytornado)
- 【逆向分析】C语言指针部分简单学习
猜你喜欢
Buuctf [gxyctf2019] no dolls
Thinkphp6 learning experience
Koa2 fast build server
Realization of interface displacement by linear Schrodinger equation
WAP green legend building (pure version)
【文件上传绕过】--二次渲染
[intranet penetration] information collection in the domain (manual +adfind tool)
【权限提升】 MSSQL提权方法
H5 online chat room
【漏洞复现】redis未授权访问windows+linux利用方法
随机推荐
VOF phase transition equation in openfoam
BUUCTF [GXYCTF2019] 禁止套娃
Buuctf n1book [Chapter 2 advanced web] file upload
[vulnerability recurrence] redis unauthorized access to windows+linux utilization method
Nodejs+express uses CORS middleware to solve cross domain problems
[intranet penetration] OpenSSL rebound traffic encrypted shell
COMSOL heat conduction method to solve maze problem (path planning)
DVWA [SQL injection (blind)] learning record
PHP arrays are arranged in descending order according to the keys of the associative array
PHP intercepts the contents before and after the specified string
Méthode d'autorisation MSSQL
Help the great God
【逆向分析】C语言指针部分简单学习
【逆向分析】恶意代码静态分析
Web security -- file upload middleware parsing vulnerability
2021-10-23
ECSHOP vulnerability recurrence
【极客大挑战 2019】Easy,Love,Baby-SQL
Thinkphp6 learning experience
PHP (TP framework) uses Alibaba cloud OSS storage