Point Cloud Library (PCL)  1.14.1-dev
hv_papazov.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  */
36 
37 #pragma once
38 
39 #include <pcl/pcl_macros.h>
40 #include <pcl/recognition/hv/hypotheses_verification.h>
41 #include <boost/graph/adjacency_list.hpp>
42 
43 #include <memory>
44 
45 namespace pcl
46 {
47 
48  /** \brief A hypothesis verification method proposed in
49  * "An Efficient RANSAC for 3D Object Recognition in Noisy and Occluded Scenes", C. Papazov and D. Burschka, ACCV 2010
50  * \author Aitor Aldoma, Federico Tombari
51  * \ingroup recognition
52  */
53 
54  template<typename ModelT, typename SceneT>
55  class PCL_EXPORTS PapazovHV : public HypothesisVerification<ModelT, SceneT>
56  {
64 
65  float conflict_threshold_size_;
66  float penalty_threshold_;
67  float support_threshold_;
68 
69  class RecognitionModel
70  {
71  public:
72  std::vector<int> explained_; //indices vector referencing explained_by_RM_
73  typename pcl::PointCloud<ModelT>::Ptr cloud_;
74  typename pcl::PointCloud<ModelT>::Ptr complete_cloud_;
75  int bad_information_;
76  int id_;
77  };
78 
79  using RecognitionModelPtr = std::shared_ptr<RecognitionModel>;
80 
81  std::vector<int> explained_by_RM_; //represents the points of scene_cloud_ that are explained by the recognition models
82  std::vector<RecognitionModelPtr> recognition_models_;
83  std::vector<std::vector<RecognitionModelPtr>> points_explained_by_rm_; //if inner size > 1, conflict
84  std::map<int, RecognitionModelPtr> graph_id_model_map_;
85 
86  using Graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, RecognitionModelPtr>;
87  Graph conflict_graph_;
88 
89  //builds the conflict_graph
90  void buildConflictGraph();
91  //non-maxima suppresion on the conflict graph
92  void nonMaximaSuppresion();
93  //create recognition models
94  void initialize();
95 
96  public:
97  PapazovHV() : HypothesisVerification<ModelT,SceneT>() {
98  support_threshold_ = 0.1f;
99  penalty_threshold_ = 0.1f;
100  conflict_threshold_size_ = 0.02f;
101  }
102 
103  void setConflictThreshold(float t) {
104  conflict_threshold_size_ = t;
105  }
106 
107  void setSupportThreshold(float t) {
108  support_threshold_ = t;
109  }
110 
111  void setPenaltyThreshold(float t) {
112  penalty_threshold_ = t;
113  }
114 
115  //build conflict graph
116  //non-maxima supression
117  void verify() override;
118  };
119 }
120 
121 #ifdef PCL_NO_PRECOMPILE
122 #include <pcl/recognition/impl/hv/hv_papazov.hpp>
123 #endif
Abstract class for hypotheses verification methods.
A hypothesis verification method proposed in "An Efficient RANSAC for 3D Object Recognition in Noisy ...
Definition: hv_papazov.h:56
void setConflictThreshold(float t)
Definition: hv_papazov.h:103
void setSupportThreshold(float t)
Definition: hv_papazov.h:107
void setPenaltyThreshold(float t)
Definition: hv_papazov.h:111
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
Defines all the PCL and non-PCL macros used.
#define PCL_EXPORTS
Definition: pcl_macros.h:325