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 <Math/Math3d.h>
30 
31 #include <pcl/point_cloud.h>
32 #include <pcl/point_types.h>
33 
34 // stdlib
35 #include <cmath>
36 #include <string>
37 
38 class CCalibration;
39 class CByteImage;
40 
41 
42 namespace COLPTools
43 {
44  void InterpolateRotation(const Mat3d m1, const Mat3d m2, const float fWeight, Mat3d& mResult);
45  void InterpolateTransformation(const Mat3d m1, const Vec3d v1, const Mat3d m2, const Vec3d v2, const float fWeight, Mat3d& mResult, Vec3d& vResult);
46 
47  void ClusterXMeans(const std::vector<CHypothesisPoint*>& aPoints, const int nMinNumClusters, const int nMaxNumClusters, const float fBICFactor, std::vector<std::vector<CHypothesisPoint*> >& aaPointClusters);
48  void ClusterXMeans(const std::vector<Vec3d>& aPoints, const int nMinNumClusters, const int nMaxNumClusters, const float fBICFactor, std::vector<std::vector<Vec3d> >& aaPointClusters, std::vector<std::vector<int> >& aaOldIndizes);
49 
50  void FilterForegroundPoints(const std::vector<CHypothesisPoint*>& aAllPoints, const CByteImage* pForegroundImage, const CCalibration* calibration, std::vector<CHypothesisPoint*>& aForegroundPoints);
51  bool PointIsInForeground(const CHypothesisPoint* pPoint, const CByteImage* pForegroundImage, const CCalibration* calibration);
52  bool PointIsInForeground(const Vec3d vPoint, const CByteImage* pForegroundImage, const CCalibration* calibration);
53  void CalculateForegroundRatioOfHypothesis(const CObjectHypothesis* pHypothesis, const CByteImage* pForegroundImage, const CCalibration* calibration, float& fForegroundRatio, int& nNumForegroundPixels);
54  void GetEnclosingRectangle(const Vec2d* pPoints, const int nNumPoints, const bool bUseSecondMaxPoints, Vec2d& p1, Vec2d& p2, Vec2d& p3, Vec2d& p4, bool& bRotated);
55  int CountForegroundPixelsInRectangle(const Vec2d vMiddleMin, const Vec2d vMinMiddle, const Vec2d vMaxMiddle, const Vec2d vMiddleMax, const CByteImage* pForegroundImage);
56 
57  void GetMeanAndVariance(const std::vector<CHypothesisPoint*>& pHypothesisPoints, Vec3d& vMean, float& fVariance);
58  void GetMeanAndVariance(const std::vector<Vec3d>& aPoints, Vec3d& vMean, float& fVariance);
59  void RemoveOutliers(std::vector<Vec3d>& aPoints, const float fStdDevFactor, std::vector<int>* pOldIndices);
60  void RemoveOutliers(std::vector<CHypothesisPoint*>& aPoints, const float fStdDevFactor);
61 
62  bool CheckIfPointIsAlreadyInHypothesis(const Vec3d vPoint, const CObjectHypothesis* pHypothesis);
63 
64  pcl::PointCloud<pcl::PointXYZRGBA>::Ptr ConfirmedPointsToPCL(const CObjectHypothesis* pHypothesis);
65 
66  void ConvertRGB2HSV(const unsigned char r, const unsigned char g, const unsigned char b, unsigned char& h, unsigned char& s, unsigned char& v);
67  void CreateHueAndSaturationHistogram(const CObjectHypothesis* pHypothesis, std::vector<float>& aHueHistogram, std::vector<float>& aSaturationHistogram);
68  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);
69  void SmoothHistogram(std::vector<float>& aHistogram);
70  void NormalizeHistogram(std::vector<float>& aHistogram);
71 
72  float GetHistogramDistanceL1(const std::vector<float>& aHistogram1, const std::vector<float>& aHistogram2);
73  float GetHistogramDistanceL2(const std::vector<float>& aHistogram1, const std::vector<float>& aHistogram2);
74  float GetHistogramDistanceX2(const std::vector<float>& aHistogram1, const std::vector<float>& aHistogram2);
75 
76  void DrawCross(CByteImage* pGreyImage, int x, int y, int nBrightness);
77  void DrawCross(CByteImage* pColorImage, int x, int y, int r, int g, int b);
78  void DrawFatCross(CByteImage* pColorImage, int x, int y, int r, int g, int b);
79 
80  void CreateObjectSegmentationMask(const CObjectHypothesis* pHypothesis, const CCalibration* calibration, CByteImage*& pForegroundImage);
81  void CreateSegmentationProbabilityMap(const CObjectHypothesis* pHypothesis, const CCalibration* calibration, CByteImage*& pProbabilityImage);
82 
83  void SetNumberInFileName(std::string& sFileName, int nNumber, int nNumDigits = 4);
84 
85  float GetHypothesesIntersectionRatio(const CObjectHypothesis* pHypothesis1, const CObjectHypothesis* pHypothesis2, const CCalibration* calibration);
86 
87  void DrawHypothesis(CObjectHypothesis* pHypothesis, const CCalibration* calibration, CByteImage* pImage, const int nNumFusedHypotheses = 1);
88  void FillHolesRGB(const CByteImage* pInputImage, CByteImage* pOutputImage, const int nRadius = 1);
89  void FillHolesGray(const CByteImage* pInputImage, CByteImage* pOutputImage, const int nRadius = 1);
90 
91  // Quicksort
92  void SortByPositionZ(std::vector<CHypothesisPoint*>& pHypothesisPoints);
93  void SortByPositionZ(std::vector<CHypothesisPoint*>& pHypothesisPoints, const int nLeftLimit, const int nRightLimit);
94 
95  void CalculateEdgeImageFromImageAndDisparity(CByteImage* pImageGray, CByteImage* pDisparity, CByteImage* pEdgeImage);
96 }
97 
COLPTools::InterpolateRotation
void InterpolateRotation(const Mat3d m1, const Mat3d m2, const float fWeight, Mat3d &mResult)
Definition: OLPTools.cpp:44
COLPTools::GetMeanAndVariance
void GetMeanAndVariance(const std::vector< CHypothesisPoint * > &pHypothesisPoints, Vec3d &vMean, float &fVariance)
Definition: OLPTools.cpp:699
COLPTools::CreateObjectSegmentationMask
void CreateObjectSegmentationMask(const CObjectHypothesis *pHypothesis, const CCalibration *calibration, CByteImage *&pForegroundImage)
Definition: OLPTools.cpp:1249
ObjectHypothesis.h
COLPTools::GetHistogramDistanceX2
float GetHistogramDistanceX2(const std::vector< float > &aHistogram1, const std::vector< float > &aHistogram2)
Definition: OLPTools.cpp:1172
COLPTools::SortByPositionZ
void SortByPositionZ(std::vector< CHypothesisPoint * > &aHypothesisPoints, const int nLeftLimit, const int nRightLimit)
Definition: OLPTools.cpp:1570
COLPTools::GetHistogramDistanceL2
float GetHistogramDistanceL2(const std::vector< float > &aHistogram1, const std::vector< float > &aHistogram2)
Definition: OLPTools.cpp:1157
COLPTools::GetHypothesesIntersectionRatio
float GetHypothesesIntersectionRatio(const CObjectHypothesis *pHypothesis1, const CObjectHypothesis *pHypothesis2, const CCalibration *calibration)
Definition: OLPTools.cpp:1395
COLPTools::SetNumberInFileName
void SetNumberInFileName(std::string &sFileName, int nNumber, int nNumDigits)
Definition: OLPTools.cpp:1378
GfxTL::Vec2d
VectorXD< 2, double > Vec2d
Definition: VectorXD.h:694
COLPTools::DrawCross
void DrawCross(CByteImage *pGreyImage, int x, int y, int nBrightness)
Definition: OLPTools.cpp:1189
COLPTools::GetHistogramDistanceL1
float GetHistogramDistanceL1(const std::vector< float > &aHistogram1, const std::vector< float > &aHistogram2)
Definition: OLPTools.cpp:1142
COLPTools::CalculateForegroundRatioOfHypothesis
void CalculateForegroundRatioOfHypothesis(const CObjectHypothesis *pHypothesis, const CByteImage *pForegroundImage, const CCalibration *calibration, float &fForegroundRatio, int &nNumForegroundPixels)
Definition: OLPTools.cpp:336
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:1061
COLPTools::RemoveOutliers
void RemoveOutliers(std::vector< Vec3d > &aPoints, const float fStdDevFactor, std::vector< int > *pOldIndices)
Definition: OLPTools.cpp:759
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:67
COLPTools::ConfirmedPointsToPCL
pcl::PointCloud< pcl::PointXYZRGBA >::Ptr ConfirmedPointsToPCL(const CObjectHypothesis *pHypothesis)
Definition: OLPTools.cpp:906
COLPTools::NormalizeHistogram
void NormalizeHistogram(std::vector< float > &aHistogram)
Definition: OLPTools.cpp:1122
COLPTools::FillHolesGray
void FillHolesGray(const CByteImage *pInputImage, CByteImage *pOutputImage, const int nRadius)
Definition: OLPTools.cpp:1527
COLPTools::DrawFatCross
void DrawFatCross(CByteImage *pColorImage, int x, int y, int r, int g, int b)
Definition: OLPTools.cpp:1220
COLPTools::PointIsInForeground
bool PointIsInForeground(const Vec3d vPoint, const CByteImage *pForegroundImage, const CCalibration *calibration)
Definition: OLPTools.cpp:310
COLPTools::CalculateEdgeImageFromImageAndDisparity
void CalculateEdgeImageFromImageAndDisparity(CByteImage *pImageGray, CByteImage *pDisparity, CByteImage *pEdgeImage)
Definition: OLPTools.cpp:1615
CHypothesisPoint
Definition: ObjectHypothesis.h:171
GfxTL::Vec3d
VectorXD< 3, double > Vec3d
Definition: VectorXD.h:695
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:450
COLPTools::CreateHueAndSaturationHistogram
void CreateHueAndSaturationHistogram(const CObjectHypothesis *pHypothesis, std::vector< float > &aHueHistogram, std::vector< float > &aSaturationHistogram)
Definition: OLPTools.cpp:1003
COLPTools::CreateSegmentationProbabilityMap
void CreateSegmentationProbabilityMap(const CObjectHypothesis *pHypothesis, const CCalibration *calibration, CByteImage *&pProbabilityImage)
Definition: OLPTools.cpp:1319
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:76
COLPTools
Definition: OLPTools.cpp:42
CObjectHypothesis
Definition: ObjectHypothesis.h:249
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:1481
COLPTools::DrawHypothesis
void DrawHypothesis(CObjectHypothesis *pHypothesis, const CCalibration *calibration, CByteImage *pImage, const int nNumFusedHypotheses)
Definition: OLPTools.cpp:1425
COLPTools::SmoothHistogram
void SmoothHistogram(std::vector< float > &aHistogram)
Definition: OLPTools.cpp:1095
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:969
COLPTools::FilterForegroundPoints
void FilterForegroundPoints(const std::vector< CHypothesisPoint * > &aAllPoints, const CByteImage *pForegroundImage, const CCalibration *calibration, std::vector< CHypothesisPoint * > &aForegroundPoints)
Definition: OLPTools.cpp:289
COLPTools::CountForegroundPixelsInRectangle
int CountForegroundPixelsInRectangle(const Vec2d vMiddleMin, const Vec2d vMinMiddle, const Vec2d vMaxMiddle, const Vec2d vMiddleMax, const CByteImage *pForegroundImage)
Definition: OLPTools.cpp:621
COLPTools::CheckIfPointIsAlreadyInHypothesis
bool CheckIfPointIsAlreadyInHypothesis(const Vec3d vPoint, const CObjectHypothesis *pHypothesis)
Definition: OLPTools.cpp:878
armarx::ctrlutil::s
double s(double t, double s0, double v0, double a0, double j)
Definition: CtrlUtil.h:33