HypothesisGeneration.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package
19  * @author
20  * @date
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
26 
27 #include "LCCPSegmentation.h"
28 #include "ObjectHypothesis.h"
30 
31 // IVT
32 #include <Math/Math2d.h>
33 #include <Math/Math3d.h>
34 
35 // OpenCV
36 #include <opencv2/opencv.hpp>
37 
38 // system
39 #include <ctime>
40 
41 
42 // forward declarations
43 class CSIFTFeatureCalculator;
44 class CCalibration;
45 class CByteImage;
46 class CStereoMatcher;
47 class CFloatMatrix;
48 
50 {
51 public:
52  CHypothesisGeneration(CCalibration* calibration);
54 
55  void FindObjectHypotheses(CByteImage* pImageLeftColor,
56  CByteImage* pImageRightColor,
57  CByteImage* pImageLeftGrey,
58  CByteImage* pImageRightGrey,
59  CSIFTFeatureArray& aAllSIFTPoints,
60  std::vector<CMSERDescriptor3D*>& aAllMSERs,
61  std::vector<CHypothesisPoint*>& aPointsFromDisparity,
62  CObjectHypothesisArray& aObjectHypotheses);
63 
64  CObjectHypothesis* CreatePlaneHypothesisDescriptor(const CVec3dArray& avPlanePoints,
65  std::vector<CMSERDescriptor3D*>& aMSERs,
66  std::vector<Vec3d>& aSigmaPoints,
67  const CByteImage* pLeftColorImage,
68  const CByteImage* pLeftGreyImage);
69 
70  CObjectHypothesis* CreateCylinderHypothesisDescriptor(const CVec3dArray& avCylinderPoints,
71  const Vec3d vCylinderAxis,
72  const Vec3d vCylinderCenter,
73  const float fCylinderRadius,
74  std::vector<CMSERDescriptor3D*>& aMSERs,
75  std::vector<Vec3d>& aSigmaPoints,
76  const CByteImage* pLeftColorImage,
77  const CByteImage* pLeftGreyImage);
78 
79  CObjectHypothesis* CreateSphereHypothesisDescriptor(const CVec3dArray& avSpherePoints,
80  const Vec3d vSphereCenter,
81  const float fSphereRadius,
82  std::vector<CMSERDescriptor3D*>& aMSERs,
83  std::vector<Vec3d>& aSigmaPoints,
84  const CByteImage* pLeftColorImage,
85  const CByteImage* pLeftGreyImage);
86 
87  inline float Determinant4x4(const float* pMatrix);
88 
89 private:
90  float GetVariance(const CVec3dArray& avPoints, Vec3d& vMean);
91 
92  void RemoveOutliers(CVec3dArray& avPoints,
93  float fStdDevFactor = 2.0f,
94  std::vector<int>* paIndices = NULL);
95 
96  bool FindCylinder(const CVec3dArray& avSamplePoints,
97  const CVec3dArray& avAllPoints,
98  const float fToleranceThreshold,
99  const float fMaxRadius,
100  CVec3dArray& avResultPoints,
101  Vec3d& vCylinderAxis,
102  Vec3d& vCylinderCenter,
103  float& fCylinderRadius);
104 
105  void QuickSort2DPointsX(CFloatMatrix& mPoints, int nLeft, int nRight);
106 
107  void ClusterPointsRegularGrid2D(const CVec3dArray& avPoints,
108  const CCalibration* calibration,
109  const int nNumSectionsX,
110  const int nNumSectionsY,
111  CVec3dArray*& pClusters,
112  int& nNumClusters);
113 
114  bool RANSACCylinders(const CVec3dArray& avPoints,
115  const CCalibration* calibration,
116  const float fToleranceThreshold,
117  const float fMaxRadius,
118  CVec3dArray& avCylinder);
119 
120  bool RANSACCylinders2(const CVec3dArray& avPoints,
121  const CCalibration* calibration,
122  const float fToleranceThreshold,
123  const float fMaxRadius,
124  CVec3dArray& avCylinder,
125  Vec3d& vCylinderAxis,
126  Vec3d& vCylinderCenter,
127  float& fCylinderRadius);
128 
129  bool RANSACPlane(const CVec3dArray& pointCandidates,
130  const float fRANSACThreshold,
131  const int nIterations,
132  CVec3dArray& resultPoints,
133  Vec3d& vAxis,
134  float& d);
135 
136  bool RANSACSphere(const CVec3dArray& aPointCandidates,
137  const float fRANSACThreshold,
138  const float fMaxSphereRadius,
139  const int nMaxIterations,
140  CVec3dArray& aResultPoints,
141  Vec3d& vCenter,
142  float& fRadius);
143 
144  bool CreateFeatureDescriptorForPoint(CHypothesisPoint* pPoint,
145  Vec3d vPosition,
146  std::vector<CMSERDescriptor3D*>& aMSERs,
147  std::vector<Vec3d>& aSigmaPoints,
148  const CByteImage* pLeftColorImage,
149  const CByteImage* pLeftGreyImage);
150  void AddSIFTFeatureDescriptors(CSIFTFeatureArray* pFeatures,
151  Vec2d vPoint2d,
152  const CByteImage* pLeftGreyImage);
153 
154  void ClusterXMeans(const CVec3dArray& aPoints,
155  const int nMaxNumClusters,
156  const float fBICFactor,
157  std::vector<CVec3dArray*>& aaPointClusters);
158 
159  inline void SortMSERsBySize(std::vector<CMSERDescriptor3D*>& aRegions3D);
160  inline void SortMSERsByX(std::vector<CMSERDescriptor3D*>& aRegions3D);
161  inline int FindRegionForPoint(Vec3d vPoint, std::vector<CMSERDescriptor3D*>& aRegions3D);
162 
163  inline void SortVec3dsByX(std::vector<Vec3d>& aPoints);
164  inline bool PointIsInList(Vec3d vPoint, std::vector<Vec3d>& aPoints);
165 
166  void CalculateSphere(Vec3d vPoint1,
167  Vec3d vPoint2,
168  Vec3d vPoint3,
169  Vec3d vPoint4,
170  Vec3d& vCenter,
171  float& fRadius);
172 
173 
174  CVec3dArray m_vFeaturePoints3d;
175 
176  CCalibration* calibration;
177  CSIFTFeatureCalculator* m_pSIFTFeatureCalculator;
178 
179 
180  CByteImage *m_pSaliencyImage, *m_pHypothesesCoveringImage, *m_pSaliencyHypothesisRegionsImage,
181  *m_pTempImageGray;
182 
183  // debug only
184  long m_nTimeSum;
185 
186  int m_nIterations;
187 
188 #ifdef OLP_USE_LCCP
189  LCCPSegmentationWrapper *lccpSegmentation1, *lccpSegmentation2;
190 #endif
191 
192  //FILE* m_pOutFile;
193  //FILE* m_pOutFile2;
194  //FILE* m_pOutFile3;
195 
196  //bool m_bTest;
197  //int m_nNumHypotheses;
198 };
GfxTL::Vec3d
VectorXD< 3, double > Vec3d
Definition: VectorXD.h:737
ObjectHypothesis.h
CSIFTFeatureArray
CDynamicArrayTemplate< CSIFTFeatureEntry * > CSIFTFeatureArray
Definition: ObjectHypothesis.h:164
CHypothesisGeneration::CreateCylinderHypothesisDescriptor
CObjectHypothesis * CreateCylinderHypothesisDescriptor(const CVec3dArray &avCylinderPoints, const Vec3d vCylinderAxis, const Vec3d vCylinderCenter, const float fCylinderRadius, std::vector< CMSERDescriptor3D * > &aMSERs, std::vector< Vec3d > &aSigmaPoints, const CByteImage *pLeftColorImage, const CByteImage *pLeftGreyImage)
Definition: HypothesisGeneration.cpp:2845
CHypothesisGeneration::CreateSphereHypothesisDescriptor
CObjectHypothesis * CreateSphereHypothesisDescriptor(const CVec3dArray &avSpherePoints, const Vec3d vSphereCenter, const float fSphereRadius, std::vector< CMSERDescriptor3D * > &aMSERs, std::vector< Vec3d > &aSigmaPoints, const CByteImage *pLeftColorImage, const CByteImage *pLeftGreyImage)
Definition: HypothesisGeneration.cpp:2939
CHypothesisGeneration::~CHypothesisGeneration
~CHypothesisGeneration(void)
Definition: HypothesisGeneration.cpp:87
CHypothesisGeneration::FindObjectHypotheses
void FindObjectHypotheses(CByteImage *pImageLeftColor, CByteImage *pImageRightColor, CByteImage *pImageLeftGrey, CByteImage *pImageRightGrey, CSIFTFeatureArray &aAllSIFTPoints, std::vector< CMSERDescriptor3D * > &aAllMSERs, std::vector< CHypothesisPoint * > &aPointsFromDisparity, CObjectHypothesisArray &aObjectHypotheses)
Definition: HypothesisGeneration.cpp:106
ObjectLearningByPushingDefinitions.h
CHypothesisPoint
Definition: ObjectHypothesis.h:166
LCCPSegmentation.h
CHypothesisGeneration::Determinant4x4
float Determinant4x4(const float *pMatrix)
Definition: HypothesisGeneration.cpp:3865
GfxTL::Vec2d
VectorXD< 2, double > Vec2d
Definition: VectorXD.h:736
CObjectHypothesis
Definition: ObjectHypothesis.h:244
CObjectHypothesisArray
CDynamicArrayTemplate< CObjectHypothesis * > CObjectHypothesisArray
Definition: ObjectHypothesis.h:362
CHypothesisGeneration::CHypothesisGeneration
CHypothesisGeneration(CCalibration *calibration)
Definition: HypothesisGeneration.cpp:48
CHypothesisGeneration
Definition: HypothesisGeneration.h:49
CHypothesisGeneration::CreatePlaneHypothesisDescriptor
CObjectHypothesis * CreatePlaneHypothesisDescriptor(const CVec3dArray &avPlanePoints, std::vector< CMSERDescriptor3D * > &aMSERs, std::vector< Vec3d > &aSigmaPoints, const CByteImage *pLeftColorImage, const CByteImage *pLeftGreyImage)
Definition: HypothesisGeneration.cpp:2723