Point Cloud Library (PCL) 1.12.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/pcl_macros.h>
40#include <pcl/recognition/hv/hypotheses_verification.h>
41#include <boost/graph/adjacency_list.hpp>
42
43#include <memory>
44
45namespace 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 */
52
53 template<typename ModelT, typename SceneT>
54 class PCL_EXPORTS PapazovHV : public HypothesisVerification<ModelT, SceneT>
55 {
56 using HypothesisVerification<ModelT, SceneT>::mask_;
57 using HypothesisVerification<ModelT, SceneT>::scene_cloud_downsampled_;
58 using HypothesisVerification<ModelT, SceneT>::scene_downsampled_tree_;
59 using HypothesisVerification<ModelT, SceneT>::visible_models_;
60 using HypothesisVerification<ModelT, SceneT>::complete_models_;
61 using HypothesisVerification<ModelT, SceneT>::resolution_;
62 using HypothesisVerification<ModelT, SceneT>::inliers_threshold_;
63
64 float conflict_threshold_size_;
65 float penalty_threshold_;
66 float support_threshold_;
67
68 class RecognitionModel
69 {
70 public:
71 std::vector<int> explained_; //indices vector referencing explained_by_RM_
72 typename pcl::PointCloud<ModelT>::Ptr cloud_;
73 typename pcl::PointCloud<ModelT>::Ptr complete_cloud_;
74 int bad_information_;
75 int id_;
76 };
77
78 using RecognitionModelPtr = std::shared_ptr<RecognitionModel>;
79
80 std::vector<int> explained_by_RM_; //represents the points of scene_cloud_ that are explained by the recognition models
81 std::vector<RecognitionModelPtr> recognition_models_;
82 std::vector<std::vector<RecognitionModelPtr>> points_explained_by_rm_; //if inner size > 1, conflict
83 std::map<int, RecognitionModelPtr> graph_id_model_map_;
84
85 using Graph = boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, RecognitionModelPtr>;
86 Graph conflict_graph_;
87
88 //builds the conflict_graph
89 void buildConflictGraph();
90 //non-maxima suppresion on the conflict graph
91 void nonMaximaSuppresion();
92 //create recognition models
93 void initialize();
94
95 public:
96 PapazovHV() : HypothesisVerification<ModelT,SceneT>() {
97 support_threshold_ = 0.1f;
98 penalty_threshold_ = 0.1f;
99 conflict_threshold_size_ = 0.02f;
100 }
101
102 void setConflictThreshold(float t) {
103 conflict_threshold_size_ = t;
104 }
105
106 void setSupportThreshold(float t) {
107 support_threshold_ = t;
108 }
109
110 void setPenaltyThreshold(float t) {
111 penalty_threshold_ = t;
112 }
113
114 //build conflict graph
115 //non-maxima supression
116 void verify() override;
117 };
118}
119
120#ifdef PCL_NO_PRECOMPILE
121#include <pcl/recognition/impl/hv/hv_papazov.hpp>
122#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:55
void setConflictThreshold(float t)
Definition: hv_papazov.h:102
void setSupportThreshold(float t)
Definition: hv_papazov.h:106
void setPenaltyThreshold(float t)
Definition: hv_papazov.h:110
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:323