Skip to content
Snippets Groups Projects
Commit e82dbb02 authored by Arnau Ramisa's avatar Arnau Ramisa
Browse files

exampless

parent 9dd985c2
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
This diff is collapsed.
......@@ -2,7 +2,7 @@
FIND_PACKAGE( Boost 1.40 COMPONENTS program_options REQUIRED )
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )
set(PCL_DIR "/opt/ros/fuerte/share/pcl-1.5/PCLConfig.cmake")
set(PCL_DIR "/home/aramisa/usr/local/share/pcl-1.6/PCLConfig.cmake")
find_package(PCL 1.3 REQUIRED COMPONENTS common io features )
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
......
......@@ -254,7 +254,7 @@ FindddAlgorithm::FindddAlgorithm(void)
this->desc_compute_positionsX_.clear();
this->desc_compute_positionsY_.clear();
this->set_positions_file("");
this->update_pca_matrix("");
this->update_pca_matrix("",0);
}
FindddAlgorithm::~FindddAlgorithm(void)
......@@ -273,7 +273,7 @@ FindddAlgorithm::FindddAlgorithm(FindddConfig new_cfg)
this->normalize_desc_ = new_cfg.normalize_desc; // * 0 - No norm // * 1 - L1 // * 2 - L2 // * 3 - sqrt + L2
this->use_soft_voting_ = new_cfg.use_soft_voting;
this->verbose_level_ = new_cfg.verbose_level;
this->update_pca_matrix(new_cfg.pca_file);
this->update_pca_matrix(new_cfg.pca_file, new_cfg.pca_nkeep);
}
// Main function to compute FINDDD descriptors
......@@ -435,8 +435,8 @@ void FindddAlgorithm::compute_ndescs_integral_spatial_interpolation(pcl::PointCl
*/
void about()
{
std::cout<<"Usage:\n finddd_descriptor -pcd <file_path> -centroids_file <centroids_path> -descfile <output_descfile_path> [-use_soft_voting <bool>] [-sample_each <step>] [-normalize_desc] [-desc_patch_radius <radius>] [-num_spatial_bins <num_bins_per_side>] [-positions_file <positions_file_path>] [-keep_nan] [-pca_file <file_path>]"<<std::endl;
std::cout<<"Parameters:\n -pcd <filename> Input pcd file path.\n -use_soft_voting <bool> Disable soft-voting.\n -sample_each <num_pix> Density of descriptor sampling.\n -normalize_desc <norm> 0=none 1=L1 2=L2 3=sqrt+L2.\n -desc_patch_radius <num_pix> Radius of the local patch.\n -num_spatial_bins <num_bins> Number of local bins per side (sqrt of total bins).\n -centroids_file <filename> Input centroid file path.\n -positions_file <filename> Input locations file path.\n -descfile <filename> Output descriptor file path.\n -pca_file <filename> PCA matrix filename\n";
std::cout<<"Usage:\n finddd_descriptor -pcd <file_path> -centroids_file <centroids_path> -descfile <output_descfile_path> [-use_soft_voting <bool>] [-sample_each <step>] [-normalize_desc] [-desc_patch_radius <radius>] [-num_spatial_bins <num_bins_per_side>] [-positions_file <positions_file_path>] [-keep_nan] [-pca_file <file_path>] [-pca_nkeep <num ev to keep>]"<<std::endl;
std::cout<<"Parameters:\n -pcd <filename> Input pcd file path.\n -use_soft_voting <bool> Disable soft-voting.\n -sample_each <num_pix> Density of descriptor sampling.\n -normalize_desc <norm> 0=none 1=L1 2=L2 3=sqrt+L2.\n -desc_patch_radius <num_pix> Radius of the local patch.\n -num_spatial_bins <num_bins> Number of local bins per side (sqrt of total bins).\n -centroids_file <filename> Input centroid file path.\n -positions_file <filename> Input locations file path.\n -descfile <filename> Output descriptor file path.\n -pca_file <filename> PCA matrix filename\n -pca_nkeep <num_ev_to_keep> Number of eigenvectors to keep (output dimension).\n";
}
/**
......@@ -469,12 +469,16 @@ bool parse_args(int argc, char* argv[], FindddConfig& new_conf)
new_conf.centroids_file = std::string(argv[++i]);
} else if(arg == "-pca_file") {
new_conf.pca_file = std::string(argv[++i]);
} else if(arg == "-pca_nkeep") {
new_conf.pca_nkeep = atoi(argv[++i]);
} else if(arg == "-positions_file") {
new_conf.positions_file = std::string(argv[++i]);
} else if(arg == "-descfile") {
new_conf.geofvecs_file = std::string(argv[++i]);
} else if(arg == "-keep_nan") {
new_conf.keep_nan_points = 1;
} else if(arg == "-ascii") {
new_conf.save_in_ascii = 1;
} else {
std::cerr<<"Unknown argument: "<<arg<<"."<<std::endl;
return false;
......@@ -501,6 +505,28 @@ bool parse_args(int argc, char* argv[], FindddConfig& new_conf)
return false;
}
/**
* \param pf File pointer where to save the data.
* \param point Descriptor to be saved.
*
* Function to write a descriptor to a file pointer in fvec format (see the yael library for more details: https://gforge.inria.fr/projects/yael/)
* Save descs in fvec format.
*/
void write_point_ascii(FILE *pf, const Descriptor &point)
{
int dim=point.descriptor.size();
if (fprintf(pf, "%d %d %d ", point.u, point.v, dim)<0)
{
fprintf(stderr, "Error writting to file\n"); exit(-1);
}
for(unsigned int j=0;j<dim-2;j++)
if (fprintf(pf, "%f ", point.descriptor[j])<0)
{
fprintf(stderr, "Error writting to file\n"); exit(-1);
}
fprintf(pf, "\n");
}
/**
* \param pf File pointer where to save the data.
* \param point Descriptor to be saved.
......@@ -543,7 +569,11 @@ void write_point_fvec(FILE *pf, const Descriptor &point)
*/
void write_feats(std::string &output_file, DescriptorSet &descriptor_set, FindddConfig &conf)
{
FILE* pf=fopen(output_file.c_str(),"wb");
FILE* pf=0;
if(conf.save_in_ascii)
pf=fopen(output_file.c_str(),"w");
else
pf=fopen(output_file.c_str(),"wb");
int saved_points = 0;
for(int ii=0;ii<descriptor_set.num;ii++)
......@@ -553,7 +583,8 @@ void write_feats(std::string &output_file, DescriptorSet &descriptor_set, Finddd
!isnan(descriptor_set.descriptors[ii].point3d.z)) ||
conf.keep_nan_points)
{
write_point_fvec(pf, descriptor_set.descriptors[ii]);
if(conf.save_in_ascii) write_point_ascii(pf, descriptor_set.descriptors[ii]);
else write_point_fvec(pf, descriptor_set.descriptors[ii]);
saved_points++;
}
}
......
......@@ -128,9 +128,12 @@ public:
int keep_nan_points;
/** Name of a file containing the mean and the PCA matrix to automatically compress the computed descriptors. If not specified no compression is done. */
std::string pca_file;
/** Number of eigenvectors to keep in the PCA matrix (=0 to keep all of them). */
int pca_nkeep;
/** Verbosity level. */
int verbose_level;
/** save descriptors in ascii format */
int save_in_ascii;
FindddConfig()
{
verbose_level=1;
......@@ -145,6 +148,8 @@ public:
geofvecs_file="";
keep_nan_points=0;
pca_file="";
pca_nkeep=0;
save_in_ascii=0;
}
};
......@@ -186,6 +191,8 @@ protected:
std::string positions_file_;
/** Name of file with mean and PCA matrix to compress descriptors on the fly. If not specified no compression is done. */
std::string pca_file_;
/** Number of eigenvectors to keep in the PCA matrix (=0 to keep all of them)*/
int pca_nkeep_;
/** Normalization of new descriptors:
0 - No norm
1 - L1
......@@ -285,9 +292,10 @@ protected:
* the PCA matrix.
*
*/
inline void update_pca_matrix(std::string new_pca_matrix_file)
inline void update_pca_matrix(std::string new_pca_matrix_file, int pca_nkeep)
{
this->pca_file_ = new_pca_matrix_file;
this->pca_nkeep_=pca_nkeep;
if(new_pca_matrix_file=="")
return;
std::ifstream ifs(this->pca_file_.c_str(), std::ifstream::in);
......@@ -343,10 +351,15 @@ protected:
std::cout<<"Not consistent PCA data: mean vector size: "<<this->pca_mean_.size()<<" PCA matrix size: "<<this->pca_matrix_.size()<<"x"<<pca_matrix_[0].size()<<std::endl;
exit(-1);
}
//matrix correctly loaded, transposing for ease of use later
//matrix correctly loaded, keeping only relevant eigenvectors and transposing for ease of use later
int nkeep=0;
if(pca_nkeep>0)
nkeep=pca_nkeep>this->pca_matrix_.size()?this->pca_matrix_.size():pca_nkeep; //min
else
nkeep=this->pca_matrix_.size();
std::vector< std::vector<float> > PCA_t;
PCA_t.resize(this->pca_matrix_[0].size(), std::vector<float>(this->pca_matrix_.size()));
for(int i=0;i<this->pca_matrix_[0].size();i++)
PCA_t.resize(nkeep, std::vector<float>(this->pca_matrix_.size()));
for(int i=0;i<nkeep;i++)
for(int j=0;j<this->pca_matrix_.size();j++)
{
PCA_t[i][j]=this->pca_matrix_[j][i];
......@@ -373,10 +386,11 @@ protected:
std::vector<float>::iterator o_it = o.begin();
for(std::vector< std::vector<float> >::iterator PCA_it=PCA.begin(); PCA_it!=PCA.end(); PCA_it++)
{
for(std::vector<float>::iterator v_it=v.begin(), pcav_it=PCA_it->begin(); v_it!=v.end(); v_it++, pcav_it++)
for(std::vector<float>::iterator v_it=v.begin(), pcav_it=PCA_it->begin(), m_it=mean.begin(); v_it!=v.end(); v_it++, pcav_it++, m_it++)
{
o_it += *v_it * *pcav_it;
*o_it += (*v_it-*m_it) * *pcav_it;
}
o_it++;
}
return o;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment