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