您的位置:首页 > 其它

如何生成vfh特征值pcd文件

2015-08-08 11:17 225 查看
参考代码见http://www.pclcn.org/study/shownews.php?lang=cn&id=95http://www.pcl-users.org/vfh-problem-td4021827.htmlhttp://pointclouds.org/documentation/tutorials/pfh_estimation.php中的代码进行修改而来

全部代码:pcd_vfh.cpp

#include <pcl/point_types.h>

#include <pcl/features/vfh.h>
#include <pcl/features/normal_3d.h>

#include <boost/thread/thread.hpp>

#include <pcl/common/common_headers.h>

#include <pcl/io/pcd_io.h>

#include <pcl/console/parse.h>

#include <pcl/visualization/pcl_visualizer.h>

#include <pcl/features/vfh.h>
int main(int argc, char** argv)
{

//--Simple cloud creation
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
//--load pcd from h.d.d
pcl::io::loadPCDFile ("E:/test9.pcd", *cloud);
cloud->width = (int) cloud->points.size ();
cloud->height = 1;

// Create the normal estimation class, and pass the input dataset to it
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> ne;
ne.setInputCloud (cloud);
pcl::search::KdTree<pcl::PointXYZ>::Ptr tree_normal (new pcl::search::KdTree<pcl::PointXYZ> ());
ne.setSearchMethod (tree_normal);
pcl::PointCloud<pcl::Normal>::Ptr cloud_normals (new pcl::PointCloud<pcl::Normal>);
ne.setRadiusSearch (0.03);
ne.compute (*cloud_normals);

// Create the VFH estimation class, and pass the input dataset+normals to it
pcl::VFHEstimation<pcl::PointXYZ, pcl::Normal, pcl::VFHSignature308> vfh;
vfh.setInputCloud (cloud);
vfh.setInputNormals (cloud_normals);
// alternatively, if cloud is of tpe PointNormal, do vfh.setInputNormals (cloud);

// Create an empty kdtree representation, and pass it to the FPFH estimation object.
// Its content will be filled inside the object, based on the given input dataset (as no other search surface is given).

<span class="n">pcl</span><span class="o">::</span><span class="n">search</span><span class="o">::</span><span class="n">KdTree</span><span class="o"><</span><span class="n">pcl</span><span class="o">::</span><span class="n">PointXYZ</span><span class="o">>::</span><span class="n">Ptr</span> <span class="n">tree</span> <span class="p">(</span><span class="k">new</span> <span class="n">pcl</span><span class="o">::</span><span class="n">search</span><span class="o">::</span><span class="n">KdTree</span><span class="o"><</span><span class="n">pcl</span><span class="o">::</span><span class="n">PointXYZ</span><span class="o">></span> <span class="p">());</span>
 <span class="c1">//pcl::KdTreeFLANN<pcl::PointXYZ>::Ptr tree (new pcl::KdTreeFLANN<pcl::PointXYZ> ()); -- older call for PCL 1.5-</span>
       vfh.setSearchMethod(tree_);

// Output datasets
pcl::PointCloud<pcl::VFHSignature308>::Ptr vfhs (new pcl::PointCloud<pcl::VFHSignature308> ());

// Compute the features
vfh.compute (*vfhs);
pcl::io::savePCDFileASCII("test_vfh.pcd",*vfhs);
return 0;
}
CmakeLists.txt
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(pcd_vfh)

find_package(PCL 1.2 REQUIRED)

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

add_executable (pcd_vfh vfh.cpp)
target_link_libraries (pcd_vfh ${PCL_LIBRARIES})

可能出现的问题:



上面代码中pcl::KdTreeFLANN<pcl::PointXYZ>::Ptr tree (new pcl::KdTreeFLANN<pcl::PointXYZ> ());只能在pcl版本在1.5级以上时使用,需将CmakeLists.txt中的PCL版本
号改在1.5及以上即可(在自己安装版本号的范围内)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: