Smoothing and normal estimation based on polynomial reconstruction

255 篇文章 7 订阅
130 篇文章 2 订阅

转自:http://www.pointclouds.org/documentation/tutorials/resampling.php

This tutorial explains how a Moving Least Squares (MLS) surface reconstructionmethod can be used to smooth and resample noisy data. Please see an example inthe video below:

Some of the data irregularities (caused by small distance measurement errors)are very hard to remove using statistical analysis. To create complete models,glossy surfaces as well as occlusions in the data must be accounted for. Insituations where additional scans are impossible to acquire, a solution is touse a resampling algorithm, which attempts to recreate the missing parts of thesurface by higher order polynomial interpolations between the surrounding datapoints. By performing resampling, these small errors can be corrected and the“double walls” artifacts resulted from registering multiple scans together canbe smoothed.

_images/resampling_1.jpg

On the left side of the figure above, we see the effect or estimating surfacenormals in a dataset comprised of two registered point clouds together. Due toalignment errors, the resultant normals are noisy. On the right side we see theeffects of surface normal estimation in the same dataset after it has beensmoothed with a Moving Least Squares algorithm. Plotting the curvatures at eachpoint as a measure of the eigenvalue relationship before and after resampling,we obtain:

_images/resampling_2.jpg

To approximate the surface defined by a local neighborhood of pointsp1, p2pk at a point q we use a bivariate polynomial height functiondefined on a on a robustly computed reference plane.

The code

First, create a file, let’s say, resampling.cpp in your favoriteeditor, and place the following inside it:

#include <pcl/point_types.h>
#include <pcl/io/pcd_io.h>
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/surface/mls.h>

int
main (int argc, char** argv)
{
  // Load input file into a PointCloud<T> with an appropriate type
  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ> ());
  // Load bun0.pcd -- should be available with the PCL archive in test 
  pcl::io::loadPCDFile ("bun0.pcd", *cloud);

  // Create a KD-Tree
  pcl::search::KdTree<pcl::PointXYZ>::Ptr tree (new pcl::search::KdTree<pcl::PointXYZ>);

  // Output has the PointNormal type in order to store the normals calculated by MLS
  pcl::PointCloud<pcl::PointNormal> mls_points;

  // Init object (second point type is for the normals, even if unused)
  pcl::MovingLeastSquares<pcl::PointXYZ, pcl::PointNormal> mls;
 
  mls.setComputeNormals (true);

  // Set parameters
  mls.setInputCloud (cloud);
  mls.setPolynomialFit (true);
  mls.setSearchMethod (tree);
  mls.setSearchRadius (0.03);

  // Reconstruct
  mls.process (mls_points);

  // Save output
  pcl::io::savePCDFile ("bun0-mls.pcd", mls_points);
}

You should be able to find the input file at pcl/test/bun0.pcd.

The explanation

Now, let’s break down the code piece by piece.

  pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ> ());
  // Load bun0.pcd -- should be available with the PCL archive in test 
  pcl::io::loadPCDFile ("bun0.pcd", *cloud);

as the example PCD has only XYZ coordinates, we load it into aPointCloud<PointXYZ>. These fields are mandatory for the method, other ones areallowed and will be preserved.

  mls.setComputeNormals (true);

if normal estimation is not required, this step can be skipped.

  pcl::MovingLeastSquares<pcl::PointXYZ, pcl::PointNormal> mls;

the first template type is used for the input and output cloud. Only the XYZdimensions of the input are smoothed in the output.

  mls.setPolynomialFit (true);

polynomial fitting could be disabled for speeding up smoothing. Please consultthe code API (MovingLeastSquares) for defaultvalues and additional parameters to control the smoothing process.

  // Save output
  pcl::io::savePCDFile ("bun0-mls.pcd", mls_points);
}

if the normals and the original dimensions need to be in the same cloud, thefields have to be concatenated.

Compiling and running the program

Add the following lines to your CMakeLists.txt file:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(resampling)

find_package(PCL 1.2 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable (resampling resampling.cpp)
target_link_libraries (resampling ${PCL_LIBRARIES})

After you have made the executable, you can run it. Simply do:

$ ./resampling

You can view the smoothed cloud for example by executing:

$ pcl_viewer bun0-mls.pcd


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值