本文整理汇总了C++中NormalEstimation类的典型用法代码示例。如果您正苦于以下问题:C++ NormalEstimation类的具体用法?C++ NormalEstimation怎么用?C++ NormalEstimation使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NormalEstimation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compute
void
compute (const sensor_msgs::PointCloud2::ConstPtr &input, sensor_msgs::PointCloud2 &output,
int k, double radius)
{
// Convert data to PointCloud<T>
PointCloud<PointXYZ>::Ptr xyz (new PointCloud<PointXYZ>);
fromROSMsg (*input, *xyz);
// Estimate
TicToc tt;
tt.tic ();
print_highlight (stderr, "Computing ");
NormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
ne.setInputCloud (xyz);
// ne.setSearchMethod (pcl::search::KdTree<pcl::PointXYZ>::Ptr (new pcl::search::KdTree<pcl::PointXYZ>));
ne.setKSearch (k);
ne.setRadiusSearch (radius);
PointCloud<Normal> normals;
ne.compute (normals);
print_info ("[done, "); print_value ("%g", tt.toc ()); print_info (" ms : "); print_value ("%d", normals.width * normals.height); print_info (" points]\n");
// Convert data back
sensor_msgs::PointCloud2 output_normals;
toROSMsg (normals, output_normals);
concatenateFields (*input, output_normals, output);
}
示例2: TEST
TEST (PCL, CVFHEstimationMilk)
{
// Estimate normals first
NormalEstimation<PointXYZ, Normal> n;
PointCloud<Normal>::Ptr normals (new PointCloud<Normal> ());
n.setInputCloud (cloud_milk);
n.setSearchMethod (tree);
n.setRadiusSearch (leaf_size_ * 4); //2cm to estimate normals
n.compute (*normals);
CVFHEstimation<PointXYZ, Normal, VFHSignature308> cvfh;
cvfh.setInputCloud (cloud_milk);
cvfh.setInputNormals (normals);
cvfh.setSearchMethod (tree_milk);
cvfh.setClusterTolerance (leaf_size_ * 3);
cvfh.setEPSAngleThreshold (0.13f);
cvfh.setCurvatureThreshold (0.025f);
cvfh.setNormalizeBins (false);
cvfh.setRadiusNormals (leaf_size_ * 4);
// Object
PointCloud<VFHSignature308>::Ptr vfhs (new PointCloud<VFHSignature308> ());
// estimate
cvfh.compute (*vfhs);
EXPECT_EQ (static_cast<int>(vfhs->points.size ()), 2);
}
示例3: estimateNormals
void
estimateNormals (const typename PointCloud<PointT>::ConstPtr &input, PointCloud<Normal> &normals)
{
if (input->isOrganized ())
{
IntegralImageNormalEstimation<PointT, Normal> ne;
// Set the parameters for normal estimation
ne.setNormalEstimationMethod (ne.COVARIANCE_MATRIX);
ne.setMaxDepthChangeFactor (0.02f);
ne.setNormalSmoothingSize (20.0f);
// Estimate normals in the cloud
ne.setInputCloud (input);
ne.compute (normals);
// Save the distance map for the plane comparator
float *map=ne.getDistanceMap ();// This will be deallocated with the IntegralImageNormalEstimation object...
distance_map_.assign(map, map+input->size() ); //...so we must copy the data out
plane_comparator_->setDistanceMap(distance_map_.data());
}
else
{
NormalEstimation<PointT, Normal> ne;
ne.setInputCloud (input);
ne.setRadiusSearch (0.02f);
ne.setSearchMethod (search_);
ne.compute (normals);
}
}
示例4: cloud
void SurfaceTriangulation::perform(int ksearch)
{
PointCloud<PointXYZ>::Ptr cloud (new PointCloud<PointXYZ>);
PointCloud<PointNormal>::Ptr cloud_with_normals (new PointCloud<PointNormal>);
search::KdTree<PointXYZ>::Ptr tree;
search::KdTree<PointNormal>::Ptr tree2;
cloud->reserve(myPoints.size());
for (Points::PointKernel::const_iterator it = myPoints.begin(); it != myPoints.end(); ++it) {
if (!boost::math::isnan(it->x) && !boost::math::isnan(it->y) && !boost::math::isnan(it->z))
cloud->push_back(PointXYZ(it->x, it->y, it->z));
}
// Create search tree
tree.reset (new search::KdTree<PointXYZ> (false));
tree->setInputCloud (cloud);
// Normal estimation
NormalEstimation<PointXYZ, Normal> n;
PointCloud<Normal>::Ptr normals (new PointCloud<Normal> ());
n.setInputCloud (cloud);
//n.setIndices (indices[B);
n.setSearchMethod (tree);
n.setKSearch (ksearch);
n.compute (*normals);
// Concatenate XYZ and normal information
pcl::concatenateFields (*cloud, *normals, *cloud_with_normals);
// Create search tree
tree2.reset (new search::KdTree<PointNormal>);
tree2->setInputCloud (cloud_with_normals);
// Init objects
GreedyProjectionTriangulation<PointNormal> gp3;
// Set parameters
gp3.setInputCloud (cloud_with_normals);
gp3.setSearchMethod (tree2);
gp3.setSearchRadius (searchRadius);
gp3.setMu (mu);
gp3.setMaximumNearestNeighbors (100);
gp3.setMaximumSurfaceAngle(M_PI/4); // 45 degrees
gp3.setMinimumAngle(M_PI/18); // 10 degrees
gp3.setMaximumAngle(2*M_PI/3); // 120 degrees
gp3.setNormalConsistency(false);
gp3.setConsistentVertexOrdering(true);
// Reconstruct
PolygonMesh mesh;
gp3.reconstruct (mesh);
MeshConversion::convert(mesh, myMesh);
// Additional vertex information
//std::vector<int> parts = gp3.getPartIDs();
//std::vector<int> states = gp3.getPointStates();
}
示例5: assert
void FeatSegment::segment(const PointCloud<PointXYZRGB >::Ptr cloud, PointCloud<PointXYZRGB >::Ptr outcloud)
{
// PARAM - Lots of them
int min_pts_per_cluster = 10;
int max_pts_per_cluster = INT_MAX; //3000000;
assert(max_pts_per_cluster > 3000000); // Avoid overflow
int number_neighbours = 50; // PARAM
float radius = 0.025; // 0.025 PARAM
float angle = 0.52; // PARAM
// Required KdTrees
pcl::search::KdTree<PointXYZRGB >::Ptr NormalsTree(new pcl::search::KdTree<PointXYZRGB >);
pcl::search::KdTree<PointXYZRGB >::Ptr ClustersTree(new pcl::search::KdTree<PointXYZRGB >);
PointCloud<Normal >::Ptr CloudNormals(new PointCloud<Normal >);
NormalEstimation<PointXYZRGB, Normal > NormalsFinder;
std::vector<PointIndices > clusters;
ClustersTree->setInputCloud(cloud);
// Set normal estimation parameters
NormalsFinder.setKSearch(number_neighbours);
NormalsFinder.setSearchMethod(NormalsTree);
NormalsFinder.setInputCloud(cloud);
NormalsFinder.compute(*CloudNormals);
extractEuclideanClusters(cloud, CloudNormals, ClustersTree, radius, clusters, angle, min_pts_per_cluster, max_pts_per_cluster);
fprintf(stderr, "Number of clusters found matching the given constraints: %d.", (int)clusters.size ());
std::ofstream FileStr2;
FileStr2.open("live_segments.txt", ios::app); // NOTE: Don't add the ios:trunc flag here!
// Copy to clusters to segments
for (size_t i = 0; i < clusters.size (); ++i)
{
if(FileStr2.is_open())
{
for(int j = 0; j < clusters[i].indices.size(); ++j)
{
if(j == clusters[i].indices.size() - 1)
{
FileStr2 << clusters[i].indices.at(j) << endl;
continue; // Also break;
}
FileStr2 << clusters[i].indices.at(j) << " ";
}
FeatPointCloud * Segment = new FeatPointCloud(m_SceneCloud, clusters[i].indices, m_ConfigFName);
m_Segments.push_back(Segment);
}
else
cout << "Failed to open file.\n";
}
FileStr2.close();
}
示例6: main
int
main (int argc, char **argv)
{
bool use_device = false;
bool use_file = false;
if (argc >= 2)
use_device = true;
if (argc >= 3)
use_file = true;
NormalEstimation v;
v.run (use_device, use_file);
return 0;
}
示例7: create_normals
void create_normals (typename PointCloud<PointT>::Ptr cloud,
typename PointCloud<NormalT>::Ptr normals,
float normal_radius=0.03)
{
NormalEstimation<PointT, NormalT> nest;
cout << "[PFHTransformationStrategy::create_normals] Input cloud "
<< cloud->points.size() << " points" << endl;
nest.setInputCloud(cloud);
nest.setSearchMethod (typename search::KdTree<PointT>::Ptr
(new search::KdTree<PointT>));
nest.setRadiusSearch(normal_radius);
nest.compute(*normals);
};
示例8: getCylClusters
void getCylClusters (boost::shared_ptr<PointCloud<T> > sceneCloud, vector<boost::shared_ptr<PointCloud<T> > > &outVector) {
typedef typename pcl::search::KdTree<T>::Ptr my_KdTreePtr;
typedef typename pcl::PointCloud<T>::Ptr my_PointCloudPtr;
NormalEstimation<T, Normal> ne;
SACSegmentationFromNormals<T, Normal> seg;
my_KdTreePtr tree (new pcl::search::KdTree<T> ());
PointCloud<Normal>::Ptr cloud_normals (new PointCloud<pcl::Normal>);
ModelCoefficients::Ptr coefficients_cylinder (new pcl::ModelCoefficients);
PointIndices::Ptr inliers_cylinder (new pcl::PointIndices);
ExtractIndices<T> extract;
// Estimate point normals
ne.setSearchMethod (tree);
ne.setInputCloud (sceneCloud);
ne.setKSearch (50);
ne.compute (*cloud_normals);
seg.setOptimizeCoefficients (true);
seg.setModelType (SACMODEL_CYLINDER);
seg.setMethodType (SAC_RANSAC);
seg.setNormalDistanceWeight (0.1);
seg.setMaxIterations (10000);
seg.setDistanceThreshold (0.05);
seg.setRadiusLimits (0, 0.1);
seg.setInputCloud (sceneCloud);
seg.setInputNormals (cloud_normals);
// Obtain the cylinder inliers and coefficients
seg.segment (*inliers_cylinder, *coefficients_cylinder);
cout << " Number of inliers vs total number of points " << inliers_cylinder->indices.size() << " vs " << sceneCloud->size() << endl;
// Write the cylinder inliers to disk
extract.setInputCloud (sceneCloud);
extract.setIndices (inliers_cylinder);
extract.setNegative (false);
my_PointCloudPtr cloud_cylinder (new PointCloud<T> ());
extract.filter (*cloud_cylinder);
outVector.push_back(cloud_cylinder);
}
示例9: main
/* ---[ */
int
main (int argc, char** argv)
{
if (argc < 2)
{
std::cerr << "No test file given. Please download `sac_plane_test.pcd` and pass its path to the test." << std::endl;
return (-1);
}
// Load a standard PCD file from disk
sensor_msgs::PointCloud2 cloud_blob;
if (loadPCDFile (argv[1], cloud_blob) < 0)
{
std::cerr << "Failed to read test file. Please download `sac_plane_test.pcd` and pass its path to the test." << std::endl;
return (-1);
}
fromROSMsg (cloud_blob, *cloud_);
indices_.resize (cloud_->points.size ());
for (size_t i = 0; i < indices_.size (); ++i) { indices_[i] = int (i); }
// Estimate surface normals
NormalEstimation<PointXYZ, Normal> n;
search::Search<PointXYZ>::Ptr tree (new search::KdTree<PointXYZ>);
tree->setInputCloud (cloud_);
n.setInputCloud (cloud_);
boost::shared_ptr<vector<int> > indicesptr (new vector<int> (indices_));
n.setIndices (indicesptr);
n.setSearchMethod (tree);
n.setRadiusSearch (0.02); // Use 2cm radius to estimate the normals
n.compute (*normals_);
testing::InitGoogleTest (&argc, argv);
return (RUN_ALL_TESTS ());
}
示例10: TEST
TEST (PCL, VFHEstimation)
{
// Estimate normals first
NormalEstimation<PointXYZ, Normal> n;
PointCloud<Normal>::Ptr normals (new PointCloud<Normal> ());
// set parameters
n.setInputCloud (cloud.makeShared ());
boost::shared_ptr<vector<int> > indicesptr (new vector<int> (indices));
n.setIndices (indicesptr);
n.setSearchMethod (tree);
n.setKSearch (10); // Use 10 nearest neighbors to estimate the normals
// estimate
n.compute (*normals);
VFHEstimation<PointXYZ, Normal, VFHSignature308> vfh;
vfh.setInputNormals (normals);
// PointCloud<PointNormal> cloud_normals;
// concatenateFields (cloud, normals, cloud_normals);
// savePCDFile ("bun0_n.pcd", cloud_normals);
// Object
PointCloud<VFHSignature308>::Ptr vfhs (new PointCloud<VFHSignature308> ());
// set parameters
vfh.setInputCloud (cloud.makeShared ());
vfh.setIndices (indicesptr);
vfh.setSearchMethod (tree);
// estimate
vfh.compute (*vfhs);
EXPECT_EQ (int (vfhs->points.size ()), 1);
//for (size_t d = 0; d < 308; ++d)
// std::cerr << vfhs.points[0].histogram[d] << std::endl;
}
示例11: TEST
TEST (PCL, NormalEstimation)
{
tree.reset (new search::KdTree<PointXYZ> (false));
n.setSearchMethod (tree);
n.setKSearch (10);
n.setInputCloud (cloud.makeShared ());
PointCloud<Normal> output;
n.compute (output);
EXPECT_EQ (output.points.size (), cloud.points.size ());
EXPECT_EQ (output.width, cloud.width);
EXPECT_EQ (output.height, cloud.height);
for (size_t i = 0; i < cloud.points.size (); ++i)
{
EXPECT_NEAR (fabs (output.points[i].normal_x), 0, 1e-2);
EXPECT_NEAR (fabs (output.points[i].normal_y), 0, 1e-2);
EXPECT_NEAR (fabs (output.points[i].normal_z), 1.0, 1e-2);
}
}
示例12: computeFeatureViaNormals
void
computeFeatureViaNormals (const pcl::PCLPointCloud2::ConstPtr &input, pcl::PCLPointCloud2 &output,
int argc, char** argv, bool set_search_flag = true)
{
int n_k = default_n_k;
int f_k = default_f_k;
double n_radius = default_n_radius;
double f_radius = default_f_radius;
parse_argument (argc, argv, "-n_k", n_k);
parse_argument (argc, argv, "-n_radius", n_radius);
parse_argument (argc, argv, "-f_k", f_k);
parse_argument (argc, argv, "-f_radius", f_radius);
// Convert data to PointCloud<PointIn>
typename PointCloud<PointIn>::Ptr xyz (new PointCloud<PointIn>);
fromPCLPointCloud2 (*input, *xyz);
// Estimate
TicToc tt;
tt.tic ();
print_highlight (stderr, "Computing ");
NormalEstimation<PointIn, NormalT> ne;
ne.setInputCloud (xyz);
ne.setSearchMethod (typename pcl::search::KdTree<PointIn>::Ptr (new pcl::search::KdTree<PointIn>));
ne.setKSearch (n_k);
ne.setRadiusSearch (n_radius);
typename PointCloud<NormalT>::Ptr normals = typename PointCloud<NormalT>::Ptr (new PointCloud<NormalT>);
ne.compute (*normals);
FeatureAlgorithm feature_est;
feature_est.setInputCloud (xyz);
feature_est.setInputNormals (normals);
feature_est.setSearchMethod (typename pcl::search::KdTree<PointIn>::Ptr (new pcl::search::KdTree<PointIn>));
PointCloud<PointOut> output_features;
if (set_search_flag) {
feature_est.setKSearch (f_k);
feature_est.setRadiusSearch (f_radius);
}
feature_est.compute (output_features);
print_info ("[done, ");
print_value ("%g", tt.toc ());
print_info (" ms : ");
print_value ("%d", output.width * output.height);
print_info (" points]\n");
// Convert data back
toPCLPointCloud2 (output_features, output);
}
示例13: compute_pcn
/** estimate the normals of a point cloud */
static PointCloud<Normal>::Ptr
compute_pcn(PointCloud<PointXYZ>::ConstPtr in, float vx, float vy, float vz)
{
PointCloud<Normal>::Ptr pcn (new PointCloud<Normal>());
NormalEstimation<PointXYZ, Normal> ne;
search::KdTree<PointXYZ>::Ptr kdt (new search::KdTree<PointXYZ>());
ne.setInputCloud(in);
ne.setSearchMethod(kdt);
ne.setKSearch(20);
ne.setViewPoint(vx, vy, vz);
ne.compute(*pcn);
return pcn;
}
示例14: removeNaNFromPointCloud
// Subsample cloud for faster matching and processing, while filling in normals.
void PointcloudProc::reduceCloud(const PointCloud<PointXYZRGB>& input, PointCloud<PointXYZRGBNormal>& output) const
{
PointCloud<PointXYZRGB> cloud_nan_filtered, cloud_box_filtered, cloud_voxel_reduced;
PointCloud<Normal> normals;
PointCloud<PointXYZRGBNormal> cloud_normals;
std::vector<int> indices;
// Filter out nans.
removeNaNFromPointCloud(input, cloud_nan_filtered, indices);
indices.clear();
// Filter out everything outside a [200x200x200] box.
Eigen::Vector4f min_pt(-100, -100, -100, -100);
Eigen::Vector4f max_pt(100, 100, 100, 100);
getPointsInBox(cloud_nan_filtered, min_pt, max_pt, indices);
ExtractIndices<PointXYZRGB> boxfilter;
boxfilter.setInputCloud(boost::make_shared<const PointCloud<PointXYZRGB> >(cloud_nan_filtered));
boxfilter.setIndices (boost::make_shared<vector<int> > (indices));
boxfilter.filter(cloud_box_filtered);
// Reduce pointcloud
VoxelGrid<PointXYZRGB> voxelfilter;
voxelfilter.setInputCloud (boost::make_shared<const PointCloud<PointXYZRGB> > (cloud_box_filtered));
voxelfilter.setLeafSize (0.05, 0.05, 0.05);
// voxelfilter.setLeafSize (0.1, 0.1, 0.1);
voxelfilter.filter (cloud_voxel_reduced);
// Compute normals
NormalEstimation<PointXYZRGB, Normal> normalest;
normalest.setViewPoint(0, 0, 0);
normalest.setSearchMethod (boost::make_shared<search::KdTree<PointXYZRGB> > ());
//normalest.setKSearch (10);
normalest.setRadiusSearch (0.25);
// normalest.setRadiusSearch (0.4);
normalest.setInputCloud(boost::make_shared<const PointCloud<PointXYZRGB> >(cloud_voxel_reduced));
normalest.compute(normals);
pcl::concatenateFields (cloud_voxel_reduced, normals, cloud_normals);
// Filter based on curvature
PassThrough<PointXYZRGBNormal> normalfilter;
normalfilter.setFilterFieldName("curvature");
// normalfilter.setFilterLimits(0.0, 0.2);
normalfilter.setFilterLimits(0.0, 0.2);
normalfilter.setInputCloud(boost::make_shared<const PointCloud<PointXYZRGBNormal> >(cloud_normals));
normalfilter.filter(output);
}
示例15: main
/* ---[ */
int
main (int argc, char** argv)
{
// Load two standard PCD files from disk
if (argc < 3)
{
std::cerr << "No test files given. Please download `sac_plane_test.pcd` and 'cturtle.pcd' and pass them path to the test." << std::endl;
return (-1);
}
// Load in the point clouds
io::loadPCDFile (argv[1], *cloud_walls);
io::loadPCDFile (argv[2], *cloud_turtle);
// Compute the normals for each cloud, and then clean them up of any NaN values
NormalEstimation<PointXYZ,PointNormal> ne;
ne.setInputCloud (cloud_walls);
ne.setRadiusSearch (0.05);
ne.compute (*cloud_walls_normals);
copyPointCloud (*cloud_walls, *cloud_walls_normals);
std::vector<int> aux_indices;
removeNaNFromPointCloud (*cloud_walls_normals, *cloud_walls_normals, aux_indices);
removeNaNNormalsFromPointCloud (*cloud_walls_normals, *cloud_walls_normals, aux_indices);
ne = NormalEstimation<PointXYZ, PointNormal> ();
ne.setInputCloud (cloud_turtle);
ne.setKSearch (5);
ne.compute (*cloud_turtle_normals);
copyPointCloud (*cloud_turtle, *cloud_turtle_normals);
removeNaNFromPointCloud (*cloud_turtle_normals, *cloud_turtle_normals, aux_indices);
removeNaNNormalsFromPointCloud (*cloud_turtle_normals, *cloud_turtle_normals, aux_indices);
testing::InitGoogleTest (&argc, argv);
return (RUN_ALL_TESTS ());
}