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 
28 #include "ObjectHypothesis.h"
29 #include "LCCPSegmentation.h"
30 
31 // IVT
32 #include <Math/Math3d.h>
33 #include <Math/Math2d.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 
49 
51 {
52 public:
53  CHypothesisGeneration(CCalibration* calibration);
55 
56  void FindObjectHypotheses(CByteImage* pImageLeftColor, CByteImage* pImageRightColor, CByteImage* pImageLeftGrey, CByteImage* pImageRightGrey,
57  CSIFTFeatureArray& aAllSIFTPoints, std::vector<CMSERDescriptor3D*>& aAllMSERs, std::vector<CHypothesisPoint*>& aPointsFromDisparity,
58  CObjectHypothesisArray& aObjectHypotheses);
59 
60  CObjectHypothesis* CreatePlaneHypothesisDescriptor(const CVec3dArray& avPlanePoints, std::vector<CMSERDescriptor3D*>& aMSERs,
61  std::vector<Vec3d>& aSigmaPoints, const CByteImage* pLeftColorImage, const CByteImage* pLeftGreyImage);
62 
63  CObjectHypothesis* CreateCylinderHypothesisDescriptor(const CVec3dArray& avCylinderPoints, const Vec3d vCylinderAxis, const Vec3d vCylinderCenter, const float fCylinderRadius,
64  std::vector<CMSERDescriptor3D*>& aMSERs, std::vector<Vec3d>& aSigmaPoints, const CByteImage* pLeftColorImage, const CByteImage* pLeftGreyImage);
65 
66  CObjectHypothesis* CreateSphereHypothesisDescriptor(const CVec3dArray& avSpherePoints, const Vec3d vSphereCenter, const float fSphereRadius, std::vector<CMSERDescriptor3D*>& aMSERs,
67  std::vector<Vec3d>& aSigmaPoints, const CByteImage* pLeftColorImage, const CByteImage* pLeftGreyImage);
68 
69  inline float Determinant4x4(const float* pMatrix);
70 
71 private:
72 
73  float GetVariance(const CVec3dArray& avPoints, Vec3d& vMean);
74 
75  void RemoveOutliers(CVec3dArray& avPoints, float fStdDevFactor = 2.0f, std::vector<int>* paIndices = NULL);
76 
77  bool FindCylinder(const CVec3dArray& avSamplePoints, const CVec3dArray& avAllPoints, const float fToleranceThreshold, const float fMaxRadius,
78  CVec3dArray& avResultPoints, Vec3d& vCylinderAxis, Vec3d& vCylinderCenter, float& fCylinderRadius);
79 
80  void QuickSort2DPointsX(CFloatMatrix& mPoints, int nLeft, int nRight);
81 
82  void ClusterPointsRegularGrid2D(const CVec3dArray& avPoints, const CCalibration* calibration,
83  const int nNumSectionsX, const int nNumSectionsY, CVec3dArray*& pClusters, int& nNumClusters);
84 
85  bool RANSACCylinders(const CVec3dArray& avPoints, const CCalibration* calibration,
86  const float fToleranceThreshold, const float fMaxRadius, CVec3dArray& avCylinder);
87 
88  bool RANSACCylinders2(const CVec3dArray& avPoints, const CCalibration* calibration,
89  const float fToleranceThreshold, const float fMaxRadius, CVec3dArray& avCylinder,
90  Vec3d& vCylinderAxis, Vec3d& vCylinderCenter, float& fCylinderRadius);
91 
92  bool RANSACPlane(const CVec3dArray& pointCandidates, const float fRANSACThreshold,
93  const int nIterations, CVec3dArray& resultPoints, Vec3d& vAxis, float& d);
94 
95  bool RANSACSphere(const CVec3dArray& aPointCandidates, const float fRANSACThreshold, const float fMaxSphereRadius,
96  const int nMaxIterations, CVec3dArray& aResultPoints, Vec3d& vCenter, float& fRadius);
97 
98  bool CreateFeatureDescriptorForPoint(CHypothesisPoint* pPoint, Vec3d vPosition, std::vector<CMSERDescriptor3D*>& aMSERs,
99  std::vector<Vec3d>& aSigmaPoints, const CByteImage* pLeftColorImage, const CByteImage* pLeftGreyImage);
100  void AddSIFTFeatureDescriptors(CSIFTFeatureArray* pFeatures, Vec2d vPoint2d, const CByteImage* pLeftGreyImage);
101 
102  void ClusterXMeans(const CVec3dArray& aPoints, const int nMaxNumClusters, const float fBICFactor, std::vector<CVec3dArray*>& aaPointClusters);
103 
104  inline void SortMSERsBySize(std::vector<CMSERDescriptor3D*>& aRegions3D);
105  inline void SortMSERsByX(std::vector<CMSERDescriptor3D*>& aRegions3D);
106  inline int FindRegionForPoint(Vec3d vPoint, std::vector<CMSERDescriptor3D*>& aRegions3D);
107 
108  inline void SortVec3dsByX(std::vector<Vec3d>& aPoints);
109  inline bool PointIsInList(Vec3d vPoint, std::vector<Vec3d>& aPoints);
110 
111  void CalculateSphere(Vec3d vPoint1, Vec3d vPoint2, Vec3d vPoint3, Vec3d vPoint4, Vec3d& vCenter, float& fRadius);
112 
113 
114  CVec3dArray m_vFeaturePoints3d;
115 
116  CCalibration* calibration;
117  CSIFTFeatureCalculator* m_pSIFTFeatureCalculator;
118 
119 
120  CByteImage* m_pSaliencyImage, *m_pHypothesesCoveringImage, *m_pSaliencyHypothesisRegionsImage, *m_pTempImageGray;
121 
122  // debug only
123  long m_nTimeSum;
124 
125  int m_nIterations;
126 
127 #ifdef OLP_USE_LCCP
128  LCCPSegmentationWrapper* lccpSegmentation1, *lccpSegmentation2;
129 #endif
130 
131  //FILE* m_pOutFile;
132  //FILE* m_pOutFile2;
133  //FILE* m_pOutFile3;
134 
135  //bool m_bTest;
136  //int m_nNumHypotheses;
137 };
138 
139 
ObjectHypothesis.h
CSIFTFeatureArray
CDynamicArrayTemplate< CSIFTFeatureEntry * > CSIFTFeatureArray
Definition: ObjectHypothesis.h:168
GfxTL::Vec2d
VectorXD< 2, double > Vec2d
Definition: VectorXD.h:694
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:2696
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:2781
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:110
ObjectLearningByPushingDefinitions.h
CHypothesisPoint
Definition: ObjectHypothesis.h:171
GfxTL::Vec3d
VectorXD< 3, double > Vec3d
Definition: VectorXD.h:695
LCCPSegmentation.h
CHypothesisGeneration::Determinant4x4
float Determinant4x4(const float *pMatrix)
Definition: HypothesisGeneration.cpp:3650
CObjectHypothesis
Definition: ObjectHypothesis.h:249
CObjectHypothesisArray
CDynamicArrayTemplate< CObjectHypothesis * > CObjectHypothesisArray
Definition: ObjectHypothesis.h:359
CHypothesisGeneration::CHypothesisGeneration
CHypothesisGeneration(CCalibration *calibration)
Definition: HypothesisGeneration.cpp:49
CHypothesisGeneration
Definition: HypothesisGeneration.h:50
CHypothesisGeneration::CreatePlaneHypothesisDescriptor
CObjectHypothesis * CreatePlaneHypothesisDescriptor(const CVec3dArray &avPlanePoints, std::vector< CMSERDescriptor3D * > &aMSERs, std::vector< Vec3d > &aSigmaPoints, const CByteImage *pLeftColorImage, const CByteImage *pLeftGreyImage)
Definition: HypothesisGeneration.cpp:2581