I am trying to use Normal Estimation for finding normals at points in clouds so that I can pass it to the FPFH keypoint detector. Here is my code:-
#include <pcl/io/pcd_io.h>
#include <pcl/features/normal_3d.h>
#include <pcl/features/fpfh.h>
int
main(int argc, char** argv)
{
// Object for storing the point cloud.
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
// Object for storing the normals.
pcl::PointCloud<pcl::Normal>::Ptr normals(new pcl::PointCloud<pcl::Normal>);
// Object for storing the FPFH descriptors for each point.
pcl::PointCloud<pcl::FPFHSignature33>::Ptr descriptors(new pcl::PointCloud<pcl::FPFHSignature33>());
// Read a PCD file from disk.
if (pcl::io::loadPCDFile<pcl::PointXYZ> ("/home/ashwin/pcl/test/table_scene_mug_stereo_textured.pcd", *cloud) == -1)
{
PCL_ERROR ("Couldn't read file p1.pcd \n");
return (-1);
}
std::cout << "Loaded " << cloud->width <<"x"<< cloud->height <<"="<< cloud->width*cloud->height << std::endl;
// Estimate the normals.
pcl::NormalEstimation<pcl::PointXYZ, pcl::Normal> normalEstimation;
normalEstimation.setInputCloud(cloud);
normalEstimation.setRadiusSearch(15);
pcl::search::KdTree<pcl::PointXYZ>::Ptr kdtree(new pcl::search::KdTree<pcl::PointXYZ>);
normalEstimation.setSearchMethod(kdtree);
normalEstimation.compute(*normals);
std::cout<< "Normal size: " << normals->size() << std::endl;
}
I am getting the following output:-
Loaded 640x480=307200 [pcl::KdTreeFLANN::setInputCloud] Cannot create a KDTree with an empty input cloud! Normal size: 0
As you can see input cloud has 307200 points. I am unable to understand why am I getting the 'empty input cloud' error?
Here is my CMakerLists.txt:-
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(registration_api)
find_package(PCL 1.8 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (fpfh_descriptor_trial fpfh_descriptor_trial.cpp)
target_link_libraries (fpfh_descriptor_trial ${PCL_LIBRARIES})
setRadiusSearch(15)
tosetKSearch(15)
, the code run without any problem. I don't think that line caused the problem though. It's just that radius search with a radius of 15 took too long and I killed it. – Jing Zhao