Point Cloud Library (PCL)  1.11.1
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/recognition/boost.h>
40 #include <pcl/pcl_macros.h>
41 #include <pcl/common/common.h>
42 #include <pcl/recognition/hv/hypotheses_verification.h>
43 #include <boost/graph/adjacency_list.hpp>
44 
45 #include <memory>
46 
47 namespace pcl
48 {
49 
50  /** \brief A hypothesis verification method proposed in
51  * "An Efficient RANSAC for 3D Object Recognition in Noisy and Occluded Scenes", C. Papazov and D. Burschka, ACCV 2010
52  * \author Aitor Aldoma, Federico Tombari
53  */
54 
55  template<typename ModelT, typename SceneT>
56  class PCL_EXPORTS PapazovHV : public HypothesisVerification<ModelT, SceneT>
57  {
65 
66  float conflict_threshold_size_;
67  float penalty_threshold_;
68  float support_threshold_;
69 
70  class RecognitionModel
71  {
72  public:
73  std::vector<int> explained_; //indices vector referencing explained_by_RM_
74  typename pcl::PointCloud<ModelT>::Ptr cloud_;
75  typename pcl::PointCloud<ModelT>::Ptr complete_cloud_;
76  int bad_information_;
77  int id_;
78  };
79 
80  using RecognitionModelPtr = std::shared_ptr<RecognitionModel>;
81 
82  std::vector<int> explained_by_RM_; //represents the points of scene_cloud_ that are explained by the recognition models
83  std::vector<RecognitionModelPtr> recognition_models_;
84  std::vector<std::vector<RecognitionModelPtr>> points_explained_by_rm_; //if inner size > 1, conflict
85  std::map<int, RecognitionModelPtr> graph_id_model_map_;
86 
87  using Graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, RecognitionModelPtr>;
88  Graph conflict_graph_;
89 
90  //builds the conflict_graph
91  void buildConflictGraph();
92  //non-maxima suppresion on the conflict graph
93  void nonMaximaSuppresion();
94  //create recognition models
95  void initialize();
96 
97  public:
98  PapazovHV() : HypothesisVerification<ModelT,SceneT>() {
99  support_threshold_ = 0.1f;
100  penalty_threshold_ = 0.1f;
101  conflict_threshold_size_ = 0.02f;
102  }
103 
104  void setConflictThreshold(float t) {
105  conflict_threshold_size_ = t;
106  }
107 
108  void setSupportThreshold(float t) {
109  support_threshold_ = t;
110  }
111 
112  void setPenaltyThreshold(float t) {
113  penalty_threshold_ = t;
114  }
115 
116  //build conflict graph
117  //non-maxima supression
118  void verify() override;
119  };
120 }
121 
122 #ifdef PCL_NO_PRECOMPILE
123 #include <pcl/recognition/impl/hv/hv_papazov.hpp>
124 #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:57
void setConflictThreshold(float t)
Definition: hv_papazov.h:104
void setSupportThreshold(float t)
Definition: hv_papazov.h:108
void setPenaltyThreshold(float t)
Definition: hv_papazov.h:112
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:429
Define standard C methods and C++ classes that are common to all methods.
Defines all the PCL and non-PCL macros used.
#define PCL_EXPORTS
Definition: pcl_macros.h:328