-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
I am developing a system for 3D object recognition using the point cloud library. I want to apply an ESF descriptor to a data set that I have stored locally. I am giving the folder containing data to the program as an argument. I am attaching the code for reference.
#include <pcl/io/pcd_io.h>
#include <pcl/features/esf.h>
#include <pcl/visualization/histogram_visualizer.h>
#include <pcl/visualization/pcl_plotter.h>
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/console/print.h>
#include <boost/filesystem.hpp>
#include <boost/range/iterator_range.hpp>
#include <flann/flann.h>
#include <fstream>
typedef std::pair<std::string, std::vector<float> > esf_model;
void calculateESFDescriptor(const boost::filesystem::path &path){
pcl::console::print_highlight ("Executing function: calculateESFDescriptor() \n");
// const boost::filesystem::path &path = base_dir/it->path().filename();
// Cloud for storing the object.
pcl::PointCloud<pcl::PointXYZ>::Ptr object(new pcl::PointCloud<pcl::PointXYZ>);
// Object for storing the ESF descriptor.
pcl::PointCloud<pcl::ESFSignature640>::Ptr descriptor(new pcl::PointCloud<pcl::ESFSignature640>);
// Note: you should have performed preprocessing to cluster out the object
// from the cloud, and save it to this individual file.
// Read a PCD file from disk.
if (pcl::io::loadPCDFile<pcl::PointXYZ>(path.string(), *object) != 0)
{
pcl::console::print_highlight ("Unable to read .pcd file from the directory\n");
// return -1;
}
// ESF estimation object.
pcl::ESFEstimation<pcl::PointXYZ, pcl::ESFSignature640> esf;
esf.setInputCloud(object);
esf.compute(*descriptor);
// Writing esf description file to disk
std::string output_file_name = path.string().substr(0, path.string().find_last_of('.')) + "_esf.pcd";
pcl::io::savePCDFileASCII (output_file_name, *descriptor);
std::cerr << "Saved data points to " << output_file_name << std::endl;
// return (0);
}
/** \brief Load a set of ESF features that will act as the model (training data)
* \param argc the number of arguments (pass from main ())
* \param argv the actual command line arguments (pass from main ())
* \param extension the file extension containing the ESF features
*/
void traverseDirectory(const boost::filesystem::path &base_dir, const std::string &extension){
pcl::console::print_highlight ("Executing function: traverseDirectory() \n");
if (!boost::filesystem::exists(base_dir) && !boost::filesystem::is_directory(base_dir)){
pcl::console::print_highlight ("Quitting as the directory does not exists.\n");
return;
}
int i = 0;
for (boost::filesystem::directory_iterator it (base_dir); it != boost::filesystem::directory_iterator (); ++it)
{
if (boost::filesystem::is_directory(it->status()))
{
std::stringstream ss;
ss << it->path ();
pcl::console::print_highlight ("Loading %s \n", ss.str().c_str());
traverseDirectory(it->path(), extension);
}
// Calculate ESF Descriptor for each file
if (boost::filesystem::is_regular_file(it->status()) && boost::filesystem::extension(it->path())==extension)
{
calculateESFDescriptor(base_dir/it->path().filename());
pcl::console::print_highlight ("Loop execution: %d\n", i++);
}
// continue;
}
}
int main(int argc, char** argv)
{
if (argc < 2)
{
PCL_ERROR ("Need at least two parameters! Syntax is: %s [model_directory] [options]\n", argv[0]);
return (-1);
}
std::string extension(".pcd");
transform(extension.begin(), extension.end(), extension.begin(), (int(*)(int))tolower);
// std::vector<esf_model> models;
// Traversing directory to find all .pcd files and applying esf descriptor to each file
traverseDirectory(argv[1], extension);
return (0);
}
The problem is that the function calculateESFDescriptor() runs only once and then the program shuts down without any error, whereas I have multiple .pcd files in the directory and the function should execute for all the files in the directory. I want to calculate the ESF descriptor for all the files to compare them with user-given input at a later stage to calculate the accuracy. I cannot debug where I am making the mistake due to which the program cannot execute for all the files in the directory. The program runs for the whole directory when I comment out the following line. calculateESFDescriptor(base_dir/it->path().filename());
The question is if it is possible to compute descriptor for the whole directory at once or do I have to give each file as input and run the program for each file separately?