1.将扫描数据与模板对象进行配准
本例利用包含一个人的深度图像场景作为目标,与获取的脸模板数据进行对齐配准,通过模板匹配可以估计脸部在场景中的位置与姿态。
2.代码
#include <limits>
#include <fstream>
#include <vector>
#include <Eigen/Core>
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/io/pcd_io.h>
#include <pcl/kdtree/kdtree_flann.h>
#include <pcl/filters/passthrough.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/features/normal_3d.h>
#include <pcl/features/fpfh.h>
#include <pcl/registration/ia_ransac.h>
class FeatureCloud
{
public:
// A bit of shorthand
typedef pcl::PointCloud<pcl::PointXYZ> PointCloud;
typedef pcl::PointCloud<pcl::Normal> SurfaceNormals;
typedef pcl::PointCloud<pcl::FPFHSignature33> LocalFeatures;
typedef pcl::search::KdTree<pcl::PointXYZ> SearchMethod;
FeatureCloud() :
search_method_xyz_(new SearchMethod),
normal_radius_(0.02f),
feature_radius_(0.02f)
{
}
~FeatureCloud() {
}
// Process the given cloud
void
setInputCloud(PointCloud::Ptr xyz)
{
xyz_ = xyz;
processInput();
}
// Load and process the cloud in the given PCD file
void
loadInputCloud(const std::string &pcd_file)
{
xyz_ = PointCloud::Ptr(new PointCloud);
pcl::io::loadPCDFile(pcd_file, *xyz_);
processInput();
}
// Get a pointer to the cloud 3D points
PointCloud::Ptr
getPointCloud() const
{
return (xyz_);
}
// Get a pointer to the cloud of 3D surface normals
SurfaceNormals::Ptr
getSurfaceNormals() const
{
return (normals_);
}
// Get a pointer to the cloud of feature descriptors
LocalFeatures::Ptr
getLocalFeatures() const
{
return (features_);
}
protected:
// Compute the surface normals and local features
void
processInput()
{
computeSurfaceNormals();
computeLocalFeatures();
}
// Compute the surface normals
void
computeSurfaceNormals()
{
normals_ = SurfaceNormals::Ptr(