38 #include <pcl/recognition/hv/hv_papazov.h>
41 template<
typename ModelT,
typename SceneT>
47 recognition_models_.clear ();
48 graph_id_model_map_.clear ();
49 conflict_graph_.clear ();
50 explained_by_RM_.clear ();
51 points_explained_by_rm_.clear ();
54 mask_.resize (complete_models_.size ());
55 for (std::size_t i = 0; i < complete_models_.size (); i++)
59 explained_by_RM_.resize (scene_cloud_downsampled_->size ());
60 points_explained_by_rm_.resize (scene_cloud_downsampled_->size ());
63 for (std::size_t m = 0; m < complete_models_.size (); m++)
65 RecognitionModelPtr recog_model (
new RecognitionModel);
69 recog_model->id_ =
static_cast<int> (m);
73 voxel_grid.
setLeafSize (resolution_, resolution_, resolution_);
74 voxel_grid.
filter (*(recog_model->cloud_));
78 voxel_grid_complete.
setLeafSize (resolution_, resolution_, resolution_);
79 voxel_grid_complete.
filter (*(recog_model->complete_cloud_));
81 std::vector<int> explained_indices;
82 std::vector<int> outliers;
84 std::vector<float> nn_distances;
86 for (std::size_t i = 0; i < recog_model->cloud_->size (); i++)
88 if (!scene_downsampled_tree_->radiusSearch ((*recog_model->cloud_)[i], inliers_threshold_, nn_indices, nn_distances,
89 std::numeric_limits<int>::max ()))
91 outliers.push_back (
static_cast<int> (i));
95 for (std::size_t k = 0; k < nn_distances.size (); k++)
97 explained_indices.push_back (nn_indices[k]);
102 std::sort (explained_indices.begin (), explained_indices.end ());
103 explained_indices.erase (std::unique (explained_indices.begin (), explained_indices.end ()), explained_indices.end ());
105 recog_model->bad_information_ =
static_cast<int> (outliers.size ());
107 if ((
static_cast<float> (recog_model->bad_information_) /
static_cast<float> (recog_model->complete_cloud_->size ()))
108 <= penalty_threshold_ && (
static_cast<float> (explained_indices.size ())
109 /
static_cast<float> (recog_model->complete_cloud_->size ())) >= support_threshold_)
111 recog_model->explained_ = explained_indices;
112 recognition_models_.push_back (recog_model);
115 for (
const int &explained_index : explained_indices)
117 explained_by_RM_[explained_index]++;
118 points_explained_by_rm_[explained_index].push_back (recog_model);
129 template<
typename ModelT,
typename SceneT>
134 using VertexIterator =
typename boost::graph_traits<Graph>::vertex_iterator;
135 VertexIterator vi, vi_end;
136 boost::tie (vi, vi_end) = boost::vertices (conflict_graph_);
138 for (
auto next = vi; next != vi_end; next++)
140 const typename Graph::vertex_descriptor v = boost::vertex (*next, conflict_graph_);
141 typename boost::graph_traits<Graph>::adjacency_iterator ai;
142 typename boost::graph_traits<Graph>::adjacency_iterator ai_end;
144 auto current = std::static_pointer_cast<RecognitionModel> (graph_id_model_map_[
static_cast<int>(v)]);
146 bool a_better_one =
false;
147 for (boost::tie (ai, ai_end) = boost::adjacent_vertices (v, conflict_graph_); (ai != ai_end) && !a_better_one; ++ai)
149 auto neighbour = std::static_pointer_cast<RecognitionModel> (graph_id_model_map_[
static_cast<int>(*ai)]);
150 if ((neighbour->explained_.size () >= current->explained_.size ()) && mask_[neighbour->id_])
158 mask_[current->id_] =
false;
164 template<
typename ModelT,
typename SceneT>
169 for (std::size_t i = 0; i < (recognition_models_.size ()); i++)
171 const typename Graph::vertex_descriptor v = boost::add_vertex (recognition_models_[i], conflict_graph_);
172 graph_id_model_map_[
static_cast<int>(v)] = std::static_pointer_cast<RecognitionModel> (recognition_models_[i]);
176 for (std::size_t i = 0; i < recognition_models_.size (); i++)
178 for (std::size_t j = i; j < recognition_models_.size (); j++)
182 float n_conflicts = 0.f;
184 for (std::size_t k = 0; k < explained_by_RM_.size (); k++)
186 if (explained_by_RM_[k] > 1)
189 bool i_found =
false;
190 bool j_found =
false;
191 bool both_found =
false;
192 for (std::size_t kk = 0; (kk < points_explained_by_rm_[k].size ()) && !both_found; kk++)
194 if (points_explained_by_rm_[k][kk]->id_ == recognition_models_[i]->id_)
197 if (points_explained_by_rm_[k][kk]->id_ == recognition_models_[j]->id_)
200 if (i_found && j_found)
210 bool add_conflict =
false;
211 add_conflict = ((n_conflicts /
static_cast<float> (recognition_models_[i]->complete_cloud_->size ())) > conflict_threshold_size_)
212 || ((n_conflicts /
static_cast<float> (recognition_models_[j]->complete_cloud_->size ())) > conflict_threshold_size_);
216 boost::add_edge (i, j, conflict_graph_);
224 template<
typename ModelT,
typename SceneT>
229 buildConflictGraph ();
230 nonMaximaSuppresion ();
233 #define PCL_INSTANTIATE_PapazovHV(T1,T2) template class PCL_EXPORTS pcl::PapazovHV<T1,T2>;
void filter(PointCloud &output)
Calls the filtering method and returns the filtered dataset in output.
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a pointer to the input dataset.
A hypothesis verification method proposed in "An Efficient RANSAC for 3D Object Recognition in Noisy ...
VoxelGrid assembles a local 3D grid over a given PointCloud, and downsamples + filters the data.
void setLeafSize(const Eigen::Vector4f &leaf_size)
Set the voxel grid leaf size.
IndicesAllocator<> Indices
Type used for indices in PCL.