ParticleFilterRobotHandLocalisation.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 "../HandLocalisationConstants.h"
29 #include "../HandModel/HandModelV2.h"
30 #include "../HandModel/HandModeliCub.h"
31 #include "Polygon.h"
32 
33 // IVT
34 #include "Math/Math3d.h"
35 #include "Helpers/helpers.h"
36 #include "Image/ByteImage.h"
37 #include "Calibration/StereoCalibration.h"
38 
39 #include <cstdlib>
40 #include <cmath>
41 
42 #define NUMBER_OF_CUES 7
43 
44 
45 
46 namespace visionx
47 {
48 
50  {
51  // config that was evaluated
53 
54  // number of found correct pixels
56 
59 
62 
63  // results of edge detection
64  int nEdgeSum;
67 
68  // rating
69  double dPFCueRating;
70  double dRating;
72 
73  };
74 
75 
77  {
78  public:
79  // constructor
80  CParticleFilterRobotHandLocalisation(int nParticles, int nDimension, int nNumParallelThreads, CStereoCalibration* pCalibration, std::string sHandModelFileName);
81 
82  // destructor
84 
85 
86  // public methods
87 
88  void SetImages(CByteImage* pRegionImageLeft, CByteImage* pRegionImageRight, CByteImage* pSobelImageLeft, CByteImage* pSobelImageRight,
89  CByteImage* pSobelXImageLeft, CByteImage* pSobelXImageRight, CByteImage* pSobelYImageLeft, CByteImage* pSobelYImageRight);
90 
91  void UpdateModel(int nParticleIndex, int nModelIndex) override;
92  void UpdateModel(int nParticleIndex) override
93  {
94  UpdateModel(nParticleIndex, 0);
95  }
96  void PredictNewBases(double dSigmaFactor) override;
97  double CalculateProbability(int nParticleIndex, int nModelIndex) override;
98  double CalculateProbability(bool bSeparateCall = true) override
99  {
100  return CalculateProbability(0, 0);
101  }
102  void CalculateFinalProbabilities() override;
103 
104  // set the configuration of the particles
105  void SetParticleConfig(double* pConfig);
106  // set the configuration of the first half of the particles, the rest is not changed
107  void SetParticleConfigHalf(double* pConfig);
108  // set the configuration of ten percent of the particles, the rest is not changed
109  void SetConfigOfATenthOfTheParticles(int nTenthIndex, double* pConfig);
110  // set the array containing the sensor values
111  void SetSensorConfig(double* sconfig);
112  // set the allowed deviation of the particle configs from the sensor values
113  void SetAllowedDeviation(double* adeviation);
114 
115  // get a detailed rating for a config
116  void GetDetailedRating(double* pConf, DetailedPFRating* pRating);
117 
118  // calc distance between two configs
119  double DistanceBetweenConfigs(double* pOldConf, double* pNewConf);
120 
121  // set the tracking ball position and size
122  void SetTrackingBallPositions(double* dPosX, double* dPosY, double* dRadius, int nNumTrBallRegions, bool bLeftCamImage);
123 
124  private:
125  public: //TODO: make private again
126 
127  // private methods
128 
129  void CalculateRegionCue(int& region_sum, int& region_length, int nModelIndex, bool bLeftCamImage);
130  void CalculateEdgeCue(int& edge_sum, int& edge_length, double& angle_diffs, int nModelIndex, bool bLeftCamImage);
131 
132  // sum up all pixel values of camImage that are inside the polygon pol, and count the number
133  // of pixels inside the polygon
134  inline void CalculatePixelSumInPolygon(ConvexPolygonCalculations::Polygon* pol, int& region_sum, int& region_length, bool bLeftCamImage);
135 
136  inline void CalculatePixelSumOnLineSequence(Vec3d linePoints[], int nPoints, int& edge_sum, int& edge_length, double& angle_diffs, bool bLeftCamImage);
137 
138  // calculate error distance to tracking ball
139  void CalculateTrackingBallCue(double& dDistanceXY, double& dDistanceZ, int nModelIndex);
140 
141 
142  // private attributes
143 
147 
148  double* sensor_config;
150 
151 
153  //int m_nParticleIndex; // index of the particle which is to be handled next
154 
160 
163 
164  //float m_fFocalLengthX;
165  //float m_fFocalLengthY;
166  //float m_fPrincipalPointX;
167  //float m_fPrincipalPointY;
168 
173  };
174 
175 
176 }
177 
178 
179 
180 
181 
visionx::CParticleFilterRobotHandLocalisation::m_pTempBoolArrays
bool ** m_pTempBoolArrays
Definition: ParticleFilterRobotHandLocalisation.h:159
visionx::CParticleFilterRobotHandLocalisation::PredictNewBases
void PredictNewBases(double dSigmaFactor) override
Definition: ParticleFilterRobotHandLocalisation.cpp:253
visionx::CParticleFilterRobotHandLocalisation::m_pdTrackingBallPosYRight
double * m_pdTrackingBallPosYRight
Definition: ParticleFilterRobotHandLocalisation.h:170
visionx::CHandModelV2
Definition: HandModelV2.h:40
visionx::DetailedPFRating::dConfidenceOfRating
double dConfidenceOfRating
Definition: ParticleFilterRobotHandLocalisation.h:71
visionx::CParticleFilterRobotHandLocalisation::m_nNumTrackingBallRegionsRight
int m_nNumTrackingBallRegionsRight
Definition: ParticleFilterRobotHandLocalisation.h:172
visionx::CParticleFilterRobotHandLocalisation::m_pTempIntersectionPolygons
ConvexPolygonCalculations::Polygon ** m_pTempIntersectionPolygons
Definition: ParticleFilterRobotHandLocalisation.h:155
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::CParticleFilterRobotHandLocalisation::m_pProbMax
double m_pProbMax[NUMBER_OF_CUES]
Definition: ParticleFilterRobotHandLocalisation.h:162
visionx::DetailedPFRating::dResultConfig
double dResultConfig[DSHT_NUM_PARAMETERS]
Definition: ParticleFilterRobotHandLocalisation.h:52
visionx::CParticleFilterRobotHandLocalisation::m_pRegionImageRight
CByteImage * m_pRegionImageRight
Definition: ParticleFilterRobotHandLocalisation.h:145
visionx::DetailedPFRating::dEdgePercentage
double dEdgePercentage
Definition: ParticleFilterRobotHandLocalisation.h:65
visionx::DetailedPFRating::dEdgeDirection
double dEdgeDirection
Definition: ParticleFilterRobotHandLocalisation.h:66
visionx::CParticleFilterRobotHandLocalisation::SetTrackingBallPositions
void SetTrackingBallPositions(double *dPosX, double *dPosY, double *dRadius, int nNumTrBallRegions, bool bLeftCamImage)
Definition: ParticleFilterRobotHandLocalisation.cpp:212
visionx::CParticleFilterRobotHandLocalisation::SetAllowedDeviation
void SetAllowedDeviation(double *adeviation)
Definition: ParticleFilterRobotHandLocalisation.cpp:198
visionx::CParticleFilterRobotHandLocalisation::DistanceBetweenConfigs
double DistanceBetweenConfigs(double *pOldConf, double *pNewConf)
Definition: ParticleFilterRobotHandLocalisation.cpp:1006
visionx::CParticleFilterRobotHandLocalisation::m_pSobelImageRight
CByteImage * m_pSobelImageRight
Definition: ParticleFilterRobotHandLocalisation.h:145
visionx::CParticleFilterRobotHandLocalisation::GetDetailedRating
void GetDetailedRating(double *pConf, DetailedPFRating *pRating)
Definition: ParticleFilterRobotHandLocalisation.cpp:854
visionx::CParticleFilterRobotHandLocalisation::CalculateTrackingBallCue
void CalculateTrackingBallCue(double &dDistanceXY, double &dDistanceZ, int nModelIndex)
Definition: ParticleFilterRobotHandLocalisation.cpp:622
visionx::ConvexPolygonCalculations::Polygon
Definition: Polygon.h:34
visionx::CParticleFilterRobotHandLocalisation::sensor_config
double * sensor_config
Definition: ParticleFilterRobotHandLocalisation.h:148
visionx::CParticleFilterRobotHandLocalisation::m_pdTrackingBallPosYLeft
double * m_pdTrackingBallPosYLeft
Definition: ParticleFilterRobotHandLocalisation.h:170
visionx::CParticleFilterRobotHandLocalisation::m_pSobelImageLeft
CByteImage * m_pSobelImageLeft
Definition: ParticleFilterRobotHandLocalisation.h:145
visionx::CParticleFilterRobotHandLocalisation::~CParticleFilterRobotHandLocalisation
virtual ~CParticleFilterRobotHandLocalisation()
Definition: ParticleFilterRobotHandLocalisation.cpp:93
visionx::CParticleFilterRobotHandLocalisation::m_pRegionImageLeft
CByteImage * m_pRegionImageLeft
Definition: ParticleFilterRobotHandLocalisation.h:145
visionx::CParticleFilterRobotHandLocalisation::CalculateProbability
double CalculateProbability(int nParticleIndex, int nModelIndex) override
Definition: ParticleFilterRobotHandLocalisation.cpp:704
visionx::CParticleFilterRobotHandLocalisation::m_pdTrackingBallPosXLeft
double * m_pdTrackingBallPosXLeft
Definition: ParticleFilterRobotHandLocalisation.h:169
Polygon.h
visionx::CParticleFilterFrameworkParallelized
Definition: ParticleFilterFrameworkParallelized.h:33
visionx::CParticleFilterRobotHandLocalisation::CalculateFinalProbabilities
void CalculateFinalProbabilities() override
Definition: ParticleFilterRobotHandLocalisation.cpp:748
visionx::DetailedPFRating
Definition: ParticleFilterRobotHandLocalisation.h:49
visionx::CParticleFilterRobotHandLocalisation::CalculateEdgeCue
void CalculateEdgeCue(int &edge_sum, int &edge_length, double &angle_diffs, int nModelIndex, bool bLeftCamImage)
Definition: ParticleFilterRobotHandLocalisation.cpp:575
visionx::CParticleFilterRobotHandLocalisation::m_pProbMin
double m_pProbMin[NUMBER_OF_CUES]
Definition: ParticleFilterRobotHandLocalisation.h:161
visionx::CParticleFilterRobotHandLocalisation::CalculatePixelSumInPolygon
void CalculatePixelSumInPolygon(ConvexPolygonCalculations::Polygon *pol, int &region_sum, int &region_length, bool bLeftCamImage)
Definition: ParticleFilterRobotHandLocalisation.cpp:288
visionx::CParticleFilterRobotHandLocalisation
Definition: ParticleFilterRobotHandLocalisation.h:76
visionx::CParticleFilterRobotHandLocalisation::SetParticleConfigHalf
void SetParticleConfigHalf(double *pConfig)
Definition: ParticleFilterRobotHandLocalisation.cpp:157
visionx::DetailedPFRating::nEdgeSum
int nEdgeSum
Definition: ParticleFilterRobotHandLocalisation.h:64
visionx::CParticleFilterRobotHandLocalisation::m_pdTrackingBallRadiusLeft
double * m_pdTrackingBallRadiusLeft
Definition: ParticleFilterRobotHandLocalisation.h:171
GfxTL::Vec3d
VectorXD< 3, double > Vec3d
Definition: VectorXD.h:695
visionx::CParticleFilterRobotHandLocalisation::m_pHandModels
CHandModelV2 ** m_pHandModels
Definition: ParticleFilterRobotHandLocalisation.h:144
visionx::CParticleFilterRobotHandLocalisation::m_pTempVecArrays
Vec3d ** m_pTempVecArrays
Definition: ParticleFilterRobotHandLocalisation.h:156
visionx::CParticleFilterRobotHandLocalisation::m_pSobelYImageRight
CByteImage * m_pSobelYImageRight
Definition: ParticleFilterRobotHandLocalisation.h:146
visionx::DetailedPFRating::nOverallNumberOfFoundPixels
int nOverallNumberOfFoundPixels
Definition: ParticleFilterRobotHandLocalisation.h:57
visionx::DetailedPFRating::dFoundPercentageOfExpectedPixelsOfFinger
double dFoundPercentageOfExpectedPixelsOfFinger[DSHT_NUM_FINGERS]
Definition: ParticleFilterRobotHandLocalisation.h:61
visionx::CParticleFilterRobotHandLocalisation::m_pSobelXImageLeft
CByteImage * m_pSobelXImageLeft
Definition: ParticleFilterRobotHandLocalisation.h:146
visionx::CParticleFilterRobotHandLocalisation::SetImages
void SetImages(CByteImage *pRegionImageLeft, CByteImage *pRegionImageRight, CByteImage *pSobelImageLeft, CByteImage *pSobelImageRight, CByteImage *pSobelXImageLeft, CByteImage *pSobelXImageRight, CByteImage *pSobelYImageLeft, CByteImage *pSobelYImageRight)
Definition: ParticleFilterRobotHandLocalisation.cpp:129
visionx::CParticleFilterRobotHandLocalisation::allowed_deviation
double * allowed_deviation
Definition: ParticleFilterRobotHandLocalisation.h:149
visionx::CParticleFilterRobotHandLocalisation::CalculateProbability
double CalculateProbability(bool bSeparateCall=true) override
Definition: ParticleFilterRobotHandLocalisation.h:98
visionx::CParticleFilterRobotHandLocalisation::m_pSobelYImageLeft
CByteImage * m_pSobelYImageLeft
Definition: ParticleFilterRobotHandLocalisation.h:146
visionx::CParticleFilterRobotHandLocalisation::UpdateModel
void UpdateModel(int nParticleIndex, int nModelIndex) override
Definition: ParticleFilterRobotHandLocalisation.cpp:238
visionx::DetailedPFRating::dPFCueRating
double dPFCueRating
Definition: ParticleFilterRobotHandLocalisation.h:69
visionx::DetailedPFRating::dRating
double dRating
Definition: ParticleFilterRobotHandLocalisation.h:70
visionx::CParticleFilterRobotHandLocalisation::CalculatePixelSumOnLineSequence
void CalculatePixelSumOnLineSequence(Vec3d linePoints[], int nPoints, int &edge_sum, int &edge_length, double &angle_diffs, bool bLeftCamImage)
Definition: ParticleFilterRobotHandLocalisation.cpp:469
visionx::CParticleFilterRobotHandLocalisation::m_pdTrackingBallRadiusRight
double * m_pdTrackingBallRadiusRight
Definition: ParticleFilterRobotHandLocalisation.h:171
visionx::CParticleFilterRobotHandLocalisation::SetParticleConfig
void SetParticleConfig(double *pConfig)
Definition: ParticleFilterRobotHandLocalisation.cpp:145
visionx::CParticleFilterRobotHandLocalisation::m_nNumTrackingBallRegionsLeft
int m_nNumTrackingBallRegionsLeft
Definition: ParticleFilterRobotHandLocalisation.h:172
visionx::CParticleFilterRobotHandLocalisation::CParticleFilterRobotHandLocalisation
CParticleFilterRobotHandLocalisation(int nParticles, int nDimension, int nNumParallelThreads, CStereoCalibration *pCalibration, std::string sHandModelFileName)
Definition: ParticleFilterRobotHandLocalisation.cpp:37
visionx::DetailedPFRating::nNumberOfFoundPixelsOfFinger
int nNumberOfFoundPixelsOfFinger[DSHT_NUM_FINGERS]
Definition: ParticleFilterRobotHandLocalisation.h:60
visionx::CParticleFilterRobotHandLocalisation::m_pSobelXImageRight
CByteImage * m_pSobelXImageRight
Definition: ParticleFilterRobotHandLocalisation.h:146
DSHT_NUM_PARAMETERS
#define DSHT_NUM_PARAMETERS
Definition: HandLocalisationConstants.h:53
DSHT_NUM_FINGERS
#define DSHT_NUM_FINGERS
Definition: HandLocalisationConstants.h:39
visionx::CParticleFilterRobotHandLocalisation::m_ppProbabilities
double ** m_ppProbabilities
Definition: ParticleFilterRobotHandLocalisation.h:152
visionx::CParticleFilterRobotHandLocalisation::SetConfigOfATenthOfTheParticles
void SetConfigOfATenthOfTheParticles(int nTenthIndex, double *pConfig)
Definition: ParticleFilterRobotHandLocalisation.cpp:169
visionx::CParticleFilterRobotHandLocalisation::UpdateModel
void UpdateModel(int nParticleIndex) override
Definition: ParticleFilterRobotHandLocalisation.h:92
ParticleFilterFrameworkParallelized.h
visionx::DetailedPFRating::dOverallFoundPercentageOfExpectedPixels
double dOverallFoundPercentageOfExpectedPixels
Definition: ParticleFilterRobotHandLocalisation.h:58
visionx::DetailedPFRating::nNumberOfWhitePixelsInImage
int nNumberOfWhitePixelsInImage
Definition: ParticleFilterRobotHandLocalisation.h:55
NUMBER_OF_CUES
#define NUMBER_OF_CUES
Definition: ParticleFilterRobotHandLocalisation.h:42
visionx::CParticleFilterRobotHandLocalisation::m_pTempClockwiseHullPolys1
Vec3d ** m_pTempClockwiseHullPolys1
Definition: ParticleFilterRobotHandLocalisation.h:157
visionx::CParticleFilterRobotHandLocalisation::m_pTempClockwiseHullPolys2
Vec3d ** m_pTempClockwiseHullPolys2
Definition: ParticleFilterRobotHandLocalisation.h:158
visionx::CParticleFilterRobotHandLocalisation::SetSensorConfig
void SetSensorConfig(double *sconfig)
Definition: ParticleFilterRobotHandLocalisation.cpp:183
visionx::CParticleFilterRobotHandLocalisation::CalculateRegionCue
void CalculateRegionCue(int &region_sum, int &region_length, int nModelIndex, bool bLeftCamImage)
Definition: ParticleFilterRobotHandLocalisation.cpp:387
visionx::CParticleFilterRobotHandLocalisation::m_pdTrackingBallPosXRight
double * m_pdTrackingBallPosXRight
Definition: ParticleFilterRobotHandLocalisation.h:169