00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __GT2004BallSpecialist_h_
00013 #define __GT2004BallSpecialist_h_
00014
00015 #include "Tools/Math/Geometry.h"
00016 #include "Tools/Debugging/DebugImages.h"
00017 #include "Representations/Perception/ColorTable.h"
00018 #include "Representations/Perception/Image.h"
00019 #include "Representations/Perception/CameraMatrix.h"
00020 #include "Representations/Perception/BallPercept.h"
00021 #include "Modules/ImageProcessor/ImageProcessorTools/ColorCorrector.h"
00022 #include "Modules/ImageProcessor/ImageProcessorTools/BresenhamLineScan.h"
00023 #include "Tools/Math/Common.h"
00024
00025
00026
00027
00028 class GT2004BallSpecialist
00029 {
00030 public:
00031 GT2004BallSpecialist(const ColorCorrector& colorCorrector);
00032
00033
00034
00035
00036 void searchBall
00037 (
00038 const Image& image,
00039 const ColorTable& colorTable,
00040 const CameraMatrix& cameraMatrix,
00041 const CameraMatrix& prevCameraMatrix,
00042 int x, int y,
00043 BallPercept& ballPercept
00044 );
00045
00046
00047
00048
00049 unsigned char getSimilarityToOrange (unsigned char y, unsigned char u, unsigned char v)
00050 {
00051
00052
00053
00054
00055
00056
00057 unsigned char r, g, b;
00058 Image::convertFromYCbCrToRGB(y, u, v, r, g, b);
00059
00060
00061 return (unsigned char) min(max(r - 2*b - 3*max((g-r/2),0) - (3*max((r/2-g),0))/2 ,0),255);
00062 }
00063
00064 private:
00065
00066
00067
00068 class BallPoint : public Vector2<int>
00069 {
00070 public:
00071 BallPoint() : atBorder(false), greenIsClose(true), yellowIsClose(false), hardEdge(true){};
00072 bool greenIsClose;
00073 bool yellowIsClose;
00074 bool hardEdge;
00075 bool atBorder;
00076
00077 BallPoint& operator=(const Vector2<int>& other)
00078 {
00079 x = other.x;
00080 y = other.y;
00081
00082 return *this;
00083 }
00084 };
00085
00086 class BallPointList
00087 {
00088 public:
00089 BallPointList() : number(0) {};
00090
00091 enum {maxNumberOfPoints = 400};
00092 BallPoint ballPoints[maxNumberOfPoints];
00093 int number;
00094
00095 void add(const BallPoint& ballPoint);
00096
00097 BallPoint& operator[] (int i) { return ballPoints[i]; }
00098 const BallPoint& operator[] (int i) const { return ballPoints[i]; }
00099 };
00100
00101
00102 void scanForBallPoints
00103 (
00104 const Image& image,
00105 const CameraInfo& bwCameraInfo,
00106 const ColorTable& colorTable,
00107 int x, int y,
00108 BallPointList& ballPoints,
00109 int& countAmbiguous,
00110 int& countOrange,
00111 int& maxOrangePerLine,
00112 int& countPixel
00113 );
00114
00115
00116 bool findEndOfBall(
00117 const Image& image,
00118 const CameraInfo& bwCameraInfo,
00119 const ColorTable& colorTable,
00120 const BallPoint& start,
00121 const Vector2<int>& step,
00122 BallPoint& destination,
00123 int& countAmbiguous,
00124 int& countOrange,
00125 int& maxOrangePerLine,
00126 int& countPixel
00127 );
00128
00129
00130
00131
00132
00133
00134 bool createBallPerceptLevenbergMarquardt
00135 (
00136 const BallPointList& ballPoints,
00137 Vector2<int>& center,
00138 double& radius
00139 );
00140
00141
00142
00143
00144 bool checkIfPointsAreInsideBall(const BallPointList& ballPoints, Vector2<int>& center, double radius);
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 void addBallPercept
00158 (
00159 const Image& image,
00160 const CameraInfo& bwCameraInfo,
00161 const ColorTable& colorTable,
00162 const CameraMatrix& cameraMatrix,
00163 const CameraMatrix& prevCameraMatrix,
00164 const Vector2<int>& center,
00165 double radius,
00166 BallPercept& ballPercept
00167 );
00168
00169 const ColorCorrector& colorCorrector;
00170 };
00171
00172 #endif// __BallSpecialist_h_
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213