OLPTools.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 #include "ObjectHypothesis.h"
27 
28 // IVT
29 #include <pcl/point_cloud.h>
30 #include <pcl/point_types.h>
31 
32 #include <Math/Math3d.h>
33 
34 // stdlib
35 #include <cmath>
36 #include <string>
37 
38 class CCalibration;
39 class CByteImage;
40 
41 namespace COLPTools
42 {
43  void InterpolateRotation(const Mat3d m1, const Mat3d m2, const float fWeight, Mat3d& mResult);
44  void InterpolateTransformation(const Mat3d m1,
45  const Vec3d v1,
46  const Mat3d m2,
47  const Vec3d v2,
48  const float fWeight,
49  Mat3d& mResult,
50  Vec3d& vResult);
51 
52  void ClusterXMeans(const std::vector<CHypothesisPoint*>& aPoints,
53  const int nMinNumClusters,
54  const int nMaxNumClusters,
55  const float fBICFactor,
56  std::vector<std::vector<CHypothesisPoint*>>& aaPointClusters);
57  void ClusterXMeans(const std::vector<Vec3d>& aPoints,
58  const int nMinNumClusters,
59  const int nMaxNumClusters,
60  const float fBICFactor,
61  std::vector<std::vector<Vec3d>>& aaPointClusters,
62  std::vector<std::vector<int>>& aaOldIndizes);
63 
64  void FilterForegroundPoints(const std::vector<CHypothesisPoint*>& aAllPoints,
65  const CByteImage* pForegroundImage,
66  const CCalibration* calibration,
67  std::vector<CHypothesisPoint*>& aForegroundPoints);
68  bool PointIsInForeground(const CHypothesisPoint* pPoint,
69  const CByteImage* pForegroundImage,
70  const CCalibration* calibration);
71  bool PointIsInForeground(const Vec3d vPoint,
72  const CByteImage* pForegroundImage,
73  const CCalibration* calibration);
75  const CByteImage* pForegroundImage,
76  const CCalibration* calibration,
77  float& fForegroundRatio,
78  int& nNumForegroundPixels);
79  void GetEnclosingRectangle(const Vec2d* pPoints,
80  const int nNumPoints,
81  const bool bUseSecondMaxPoints,
82  Vec2d& p1,
83  Vec2d& p2,
84  Vec2d& p3,
85  Vec2d& p4,
86  bool& bRotated);
87  int CountForegroundPixelsInRectangle(const Vec2d vMiddleMin,
88  const Vec2d vMinMiddle,
89  const Vec2d vMaxMiddle,
90  const Vec2d vMiddleMax,
91  const CByteImage* pForegroundImage);
92 
93  void GetMeanAndVariance(const std::vector<CHypothesisPoint*>& pHypothesisPoints,
94  Vec3d& vMean,
95  float& fVariance);
96  void GetMeanAndVariance(const std::vector<Vec3d>& aPoints, Vec3d& vMean, float& fVariance);
97  void RemoveOutliers(std::vector<Vec3d>& aPoints,
98  const float fStdDevFactor,
99  std::vector<int>* pOldIndices);
100  void RemoveOutliers(std::vector<CHypothesisPoint*>& aPoints, const float fStdDevFactor);
101 
102  bool CheckIfPointIsAlreadyInHypothesis(const Vec3d vPoint,
103  const CObjectHypothesis* pHypothesis);
104 
105  pcl::PointCloud<pcl::PointXYZRGBA>::Ptr
106  ConfirmedPointsToPCL(const CObjectHypothesis* pHypothesis);
107 
108  void ConvertRGB2HSV(const unsigned char r,
109  const unsigned char g,
110  const unsigned char b,
111  unsigned char& h,
112  unsigned char& s,
113  unsigned char& v);
114  void CreateHueAndSaturationHistogram(const CObjectHypothesis* pHypothesis,
115  std::vector<float>& aHueHistogram,
116  std::vector<float>& aSaturationHistogram);
117  void CreateHueAndSaturationHistogramInWindow(const CByteImage* pHSVImage,
118  const int nMinX,
119  const int nMinY,
120  const int nMaxX,
121  const int nMaxY,
122  std::vector<float>& aHueHistogram,
123  std::vector<float>& aSaturationHistogram);
124  void SmoothHistogram(std::vector<float>& aHistogram);
125  void NormalizeHistogram(std::vector<float>& aHistogram);
126 
127  float GetHistogramDistanceL1(const std::vector<float>& aHistogram1,
128  const std::vector<float>& aHistogram2);
129  float GetHistogramDistanceL2(const std::vector<float>& aHistogram1,
130  const std::vector<float>& aHistogram2);
131  float GetHistogramDistanceX2(const std::vector<float>& aHistogram1,
132  const std::vector<float>& aHistogram2);
133 
134  void DrawCross(CByteImage* pGreyImage, int x, int y, int nBrightness);
135  void DrawCross(CByteImage* pColorImage, int x, int y, int r, int g, int b);
136  void DrawFatCross(CByteImage* pColorImage, int x, int y, int r, int g, int b);
137 
138  void CreateObjectSegmentationMask(const CObjectHypothesis* pHypothesis,
139  const CCalibration* calibration,
140  CByteImage*& pForegroundImage);
141  void CreateSegmentationProbabilityMap(const CObjectHypothesis* pHypothesis,
142  const CCalibration* calibration,
143  CByteImage*& pProbabilityImage);
144 
145  void SetNumberInFileName(std::string& sFileName, int nNumber, int nNumDigits = 4);
146 
147  float GetHypothesesIntersectionRatio(const CObjectHypothesis* pHypothesis1,
148  const CObjectHypothesis* pHypothesis2,
149  const CCalibration* calibration);
150 
151  void DrawHypothesis(CObjectHypothesis* pHypothesis,
152  const CCalibration* calibration,
153  CByteImage* pImage,
154  const int nNumFusedHypotheses = 1);
155  void
156  FillHolesRGB(const CByteImage* pInputImage, CByteImage* pOutputImage, const int nRadius = 1);
157  void
158  FillHolesGray(const CByteImage* pInputImage, CByteImage* pOutputImage, const int nRadius = 1);
159 
160  // Quicksort
161  void SortByPositionZ(std::vector<CHypothesisPoint*>& pHypothesisPoints);
162  void SortByPositionZ(std::vector<CHypothesisPoint*>& pHypothesisPoints,
163  const int nLeftLimit,
164  const int nRightLimit);
165 
166  void CalculateEdgeImageFromImageAndDisparity(CByteImage* pImageGray,
167  CByteImage* pDisparity,
168  CByteImage* pEdgeImage);
169 } // namespace COLPTools
COLPTools::InterpolateRotation
void InterpolateRotation(const Mat3d m1, const Mat3d m2, const float fWeight, Mat3d &mResult)
Definition: OLPTools.cpp:43
GfxTL::Vec3d
VectorXD< 3, double > Vec3d
Definition: VectorXD.h:737
COLPTools::GetMeanAndVariance
void GetMeanAndVariance(const std::vector< CHypothesisPoint * > &pHypothesisPoints, Vec3d &vMean, float &fVariance)
Definition: OLPTools.cpp:772
COLPTools::CreateObjectSegmentationMask
void CreateObjectSegmentationMask(const CObjectHypothesis *pHypothesis, const CCalibration *calibration, CByteImage *&pForegroundImage)
Definition: OLPTools.cpp:1323
ObjectHypothesis.h
COLPTools::GetHistogramDistanceX2
float GetHistogramDistanceX2(const std::vector< float > &aHistogram1, const std::vector< float > &aHistogram2)
Definition: OLPTools.cpp:1247
COLPTools::SortByPositionZ
void SortByPositionZ(std::vector< CHypothesisPoint * > &aHypothesisPoints, const int nLeftLimit, const int nRightLimit)
Definition: OLPTools.cpp:1677
COLPTools::GetHistogramDistanceL2
float GetHistogramDistanceL2(const std::vector< float > &aHistogram1, const std::vector< float > &aHistogram2)
Definition: OLPTools.cpp:1230
COLPTools::GetHypothesesIntersectionRatio
float GetHypothesesIntersectionRatio(const CObjectHypothesis *pHypothesis1, const CObjectHypothesis *pHypothesis2, const CCalibration *calibration)
Definition: OLPTools.cpp:1480
COLPTools::SetNumberInFileName
void SetNumberInFileName(std::string &sFileName, int nNumber, int nNumDigits)
Definition: OLPTools.cpp:1464
COLPTools::DrawCross
void DrawCross(CByteImage *pGreyImage, int x, int y, int nBrightness)
Definition: OLPTools.cpp:1265
COLPTools::GetHistogramDistanceL1
float GetHistogramDistanceL1(const std::vector< float > &aHistogram1, const std::vector< float > &aHistogram2)
Definition: OLPTools.cpp:1214
COLPTools::CalculateForegroundRatioOfHypothesis
void CalculateForegroundRatioOfHypothesis(const CObjectHypothesis *pHypothesis, const CByteImage *pForegroundImage, const CCalibration *calibration, float &fForegroundRatio, int &nNumForegroundPixels)
Definition: OLPTools.cpp:383
COLPTools::CreateHueAndSaturationHistogramInWindow
void CreateHueAndSaturationHistogramInWindow(const CByteImage *pHSVImage, const int nMinX, const int nMinY, const int nMaxX, const int nMaxY, std::vector< float > &aHueHistogram, std::vector< float > &aSaturationHistogram)
Definition: OLPTools.cpp:1132
COLPTools::RemoveOutliers
void RemoveOutliers(std::vector< Vec3d > &aPoints, const float fStdDevFactor, std::vector< int > *pOldIndices)
Definition: OLPTools.cpp:829
COLPTools::InterpolateTransformation
void InterpolateTransformation(const Mat3d m1, const Vec3d v1, const Mat3d m2, const Vec3d v2, const float fWeight, Mat3d &mResult, Vec3d &vResult)
Definition: OLPTools.cpp:64
COLPTools::ConfirmedPointsToPCL
pcl::PointCloud< pcl::PointXYZRGBA >::Ptr ConfirmedPointsToPCL(const CObjectHypothesis *pHypothesis)
Definition: OLPTools.cpp:979
COLPTools::NormalizeHistogram
void NormalizeHistogram(std::vector< float > &aHistogram)
Definition: OLPTools.cpp:1196
COLPTools::FillHolesGray
void FillHolesGray(const CByteImage *pInputImage, CByteImage *pOutputImage, const int nRadius)
Definition: OLPTools.cpp:1634
COLPTools::DrawFatCross
void DrawFatCross(CByteImage *pColorImage, int x, int y, int r, int g, int b)
Definition: OLPTools.cpp:1296
COLPTools::PointIsInForeground
bool PointIsInForeground(const Vec3d vPoint, const CByteImage *pForegroundImage, const CCalibration *calibration)
Definition: OLPTools.cpp:356
COLPTools::CalculateEdgeImageFromImageAndDisparity
void CalculateEdgeImageFromImageAndDisparity(CByteImage *pImageGray, CByteImage *pDisparity, CByteImage *pEdgeImage)
Definition: OLPTools.cpp:1726
CHypothesisPoint
Definition: ObjectHypothesis.h:166
COLPTools::GetEnclosingRectangle
void GetEnclosingRectangle(const Vec2d *pPoints, const int nNumPoints, const bool bUseSecondMaxPoints, Vec2d &p1, Vec2d &p2, Vec2d &p3, Vec2d &p4, bool &bRotated)
Definition: OLPTools.cpp:505
COLPTools::CreateHueAndSaturationHistogram
void CreateHueAndSaturationHistogram(const CObjectHypothesis *pHypothesis, std::vector< float > &aHueHistogram, std::vector< float > &aSaturationHistogram)
Definition: OLPTools.cpp:1071
COLPTools::CreateSegmentationProbabilityMap
void CreateSegmentationProbabilityMap(const CObjectHypothesis *pHypothesis, const CCalibration *calibration, CByteImage *&pProbabilityImage)
Definition: OLPTools.cpp:1402
COLPTools::ClusterXMeans
void ClusterXMeans(const std::vector< CHypothesisPoint * > &aPoints, const int nMinNumClusters, const int nMaxNumClusters, const float fBICFactor, std::vector< std::vector< CHypothesisPoint * >> &aaPointClusters)
Definition: OLPTools.cpp:78
GfxTL::Vec2d
VectorXD< 2, double > Vec2d
Definition: VectorXD.h:736
COLPTools
Definition: OLPTools.cpp:40
CObjectHypothesis
Definition: ObjectHypothesis.h:244
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
COLPTools::FillHolesRGB
void FillHolesRGB(const CByteImage *pInputImage, CByteImage *pOutputImage, const int nRadius)
Definition: OLPTools.cpp:1583
COLPTools::DrawHypothesis
void DrawHypothesis(CObjectHypothesis *pHypothesis, const CCalibration *calibration, CByteImage *pImage, const int nNumFusedHypotheses)
Definition: OLPTools.cpp:1516
COLPTools::SmoothHistogram
void SmoothHistogram(std::vector< float > &aHistogram)
Definition: OLPTools.cpp:1169
COLPTools::ConvertRGB2HSV
void ConvertRGB2HSV(const unsigned char r, const unsigned char g, const unsigned char b, unsigned char &h, unsigned char &s, unsigned char &v)
Definition: OLPTools.cpp:1031
COLPTools::FilterForegroundPoints
void FilterForegroundPoints(const std::vector< CHypothesisPoint * > &aAllPoints, const CByteImage *pForegroundImage, const CCalibration *calibration, std::vector< CHypothesisPoint * > &aForegroundPoints)
Definition: OLPTools.cpp:333
COLPTools::CountForegroundPixelsInRectangle
int CountForegroundPixelsInRectangle(const Vec2d vMiddleMin, const Vec2d vMinMiddle, const Vec2d vMaxMiddle, const Vec2d vMiddleMax, const CByteImage *pForegroundImage)
Definition: OLPTools.cpp:692
COLPTools::CheckIfPointIsAlreadyInHypothesis
bool CheckIfPointIsAlreadyInHypothesis(const Vec3d vPoint, const CObjectHypothesis *pHypothesis)
Definition: OLPTools.cpp:950
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33