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
38class CCalibration;
39class CByteImage;
40
41namespace 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);
74 void CalculateForegroundRatioOfHypothesis(const CObjectHypothesis* pHypothesis,
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
void ConvertRGB2HSV(const unsigned char r, const unsigned char g, const unsigned char b, unsigned char &h, unsigned char &s, unsigned char &v)
void DrawCross(CByteImage *pGreyImage, int x, int y, int nBrightness)
void CreateObjectSegmentationMask(const CObjectHypothesis *pHypothesis, const CCalibration *calibration, CByteImage *&pForegroundImage)
void CalculateEdgeImageFromImageAndDisparity(CByteImage *pImageGray, CByteImage *pDisparity, CByteImage *pEdgeImage)
float GetHistogramDistanceX2(const std::vector< float > &aHistogram1, const std::vector< float > &aHistogram2)
float GetHypothesesIntersectionRatio(const CObjectHypothesis *pHypothesis1, const CObjectHypothesis *pHypothesis2, const CCalibration *calibration)
void FilterForegroundPoints(const std::vector< CHypothesisPoint * > &aAllPoints, const CByteImage *pForegroundImage, const CCalibration *calibration, std::vector< CHypothesisPoint * > &aForegroundPoints)
Definition OLPTools.cpp:333
void CreateSegmentationProbabilityMap(const CObjectHypothesis *pHypothesis, const CCalibration *calibration, CByteImage *&pProbabilityImage)
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
void InterpolateRotation(const Mat3d m1, const Mat3d m2, const float fWeight, Mat3d &mResult)
Definition OLPTools.cpp:43
void NormalizeHistogram(std::vector< float > &aHistogram)
void DrawHypothesis(CObjectHypothesis *pHypothesis, const CCalibration *calibration, CByteImage *pImage, const int nNumFusedHypotheses)
void CalculateForegroundRatioOfHypothesis(const CObjectHypothesis *pHypothesis, const CByteImage *pForegroundImage, const CCalibration *calibration, float &fForegroundRatio, int &nNumForegroundPixels)
Definition OLPTools.cpp:383
void SortByPositionZ(std::vector< CHypothesisPoint * > &aHypothesisPoints, const int nLeftLimit, const int nRightLimit)
void GetMeanAndVariance(const std::vector< CHypothesisPoint * > &pHypothesisPoints, Vec3d &vMean, float &fVariance)
Definition OLPTools.cpp:772
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)
void FillHolesRGB(const CByteImage *pInputImage, CByteImage *pOutputImage, const int nRadius)
pcl::PointCloud< pcl::PointXYZRGBA >::Ptr ConfirmedPointsToPCL(const CObjectHypothesis *pHypothesis)
Definition OLPTools.cpp:979
int CountForegroundPixelsInRectangle(const Vec2d vMiddleMin, const Vec2d vMinMiddle, const Vec2d vMaxMiddle, const Vec2d vMiddleMax, const CByteImage *pForegroundImage)
Definition OLPTools.cpp:692
void FillHolesGray(const CByteImage *pInputImage, CByteImage *pOutputImage, const int nRadius)
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
bool CheckIfPointIsAlreadyInHypothesis(const Vec3d vPoint, const CObjectHypothesis *pHypothesis)
Definition OLPTools.cpp:950
void DrawFatCross(CByteImage *pColorImage, int x, int y, int r, int g, int b)
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
void SetNumberInFileName(std::string &sFileName, int nNumber, int nNumDigits)
bool PointIsInForeground(const Vec3d vPoint, const CByteImage *pForegroundImage, const CCalibration *calibration)
Definition OLPTools.cpp:356
void SmoothHistogram(std::vector< float > &aHistogram)
void RemoveOutliers(std::vector< Vec3d > &aPoints, const float fStdDevFactor, std::vector< int > *pOldIndices)
Definition OLPTools.cpp:829
void CreateHueAndSaturationHistogram(const CObjectHypothesis *pHypothesis, std::vector< float > &aHueHistogram, std::vector< float > &aSaturationHistogram)
float GetHistogramDistanceL2(const std::vector< float > &aHistogram1, const std::vector< float > &aHistogram2)
float GetHistogramDistanceL1(const std::vector< float > &aHistogram1, const std::vector< float > &aHistogram2)