00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __GoalRecognizer_h_
00010 #define __GoalRecognizer_h_
00011
00012 #include "Representations/Perception/Image.h"
00013 #include "Representations/Perception/CameraMatrix.h"
00014 #include "Representations/Perception/ColorTable.h"
00015 #include "Representations/Perception/ObstaclesPercept.h"
00016 #include "Representations/Perception/LandmarksPercept.h"
00017
00018
00019 #include "Tools/Math/Geometry.h"
00020 #include "Tools/Debugging/DebugImages.h"
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 class GoalRecognizer
00034 {
00035 public:
00036 GoalRecognizer(
00037 const Image& image,
00038 const CameraMatrix& cameraMatrix,
00039 const ColorTable& colorTable,
00040 ObstaclesPercept& obstaclesPercept,
00041 LandmarksPercept& landmarksPercept
00042 );
00043
00044 GoalRecognizer(
00045 const Image& image,
00046 const CameraMatrix& cameraMatrix,
00047 const ColorTable& colorTable,
00048 int goalIndicationAboveHorizon,
00049 int goalIndicationBelowHorizon,
00050 ObstaclesPercept& obstaclesPercept,
00051 LandmarksPercept& landmarksPercept
00052 );
00053
00054 ~GoalRecognizer();
00055
00056 void getGoalPercept(LandmarksPercept& landmarksPercept);
00057
00058 struct ColoredPartsCheck
00059 {
00060 Vector2<int> firstPoint;
00061 Vector2<int> lastPoint;
00062 int rangeOfColor;
00063 int numberOfColoredPixels;
00064
00065 enum{maxNumberOfParts = 20};
00066
00067 int numberOfLargeParts;
00068 int sizeOfLargePart[maxNumberOfParts];
00069 Vector2<int> largePartBegin[maxNumberOfParts];
00070 Vector2<int> largePartEnd[maxNumberOfParts];
00071 Vector2<double> largePartBeginAngles[maxNumberOfParts];
00072 Vector2<double> largePartEndAngles[maxNumberOfParts];
00073 bool largePartBeginIsOnBorder[maxNumberOfParts];
00074 bool largePartEndIsOnBorder[maxNumberOfParts];
00075
00076 ColoredPartsCheck()
00077 {
00078 numberOfLargeParts = 0;
00079 }
00080
00081 bool determineLargePart(int size, bool beginIsOnBorder, bool endIsOnBorder, CameraMatrix cameraMatrix, CameraInfo cameraInfo)
00082 {
00083 bool foundLargePart = false;
00084
00085 {
00086 if(rangeOfColor > size)
00087 {
00088 sizeOfLargePart[numberOfLargeParts] = rangeOfColor;
00089 largePartBegin[numberOfLargeParts].x = firstPoint.x;
00090 largePartBegin[numberOfLargeParts].y = firstPoint.y;
00091 largePartEnd[numberOfLargeParts].x = lastPoint.x;
00092 largePartEnd[numberOfLargeParts].y = lastPoint.y;
00093 largePartBeginIsOnBorder[numberOfLargeParts] = beginIsOnBorder;
00094 largePartEndIsOnBorder[numberOfLargeParts] = endIsOnBorder;
00095
00096 Vector2<double> minAngles, maxAngles;
00097 Geometry::calculateAnglesForPoint(largePartBegin[numberOfLargeParts], cameraMatrix, cameraInfo, largePartBeginAngles[numberOfLargeParts]);
00098 Geometry::calculateAnglesForPoint(largePartEnd[numberOfLargeParts], cameraMatrix, cameraInfo, largePartEndAngles[numberOfLargeParts]);
00099
00100 numberOfLargeParts++;
00101 foundLargePart = true;
00102 LINE(imageProcessor_flagsAndGoals, firstPoint.x, firstPoint.y, lastPoint.x, lastPoint.y,
00103 2, Drawings::ps_solid, Drawings::pink);
00104 }
00105
00106 if(numberOfLargeParts >= maxNumberOfParts)
00107 {
00108 numberOfLargeParts = maxNumberOfParts-1;
00109 }
00110 }
00111 return foundLargePart;
00112 }
00113 };
00114
00115 private:
00116
00117
00118 void calculateScanLinesParallelToHorizon();
00119
00120
00121 void calculateScanLinesParallelToHorizon(
00122 int distanceAboveHorizon,
00123 int distanceBelowHorizon,
00124 int numberOfScanLines
00125 );
00126
00127
00128 void scanHorizontalForGoals();
00129
00130
00131 void calculateVerticalGoalScanLines();
00132
00133
00134 void scanLinesForGoals();
00135
00136 DECLARE_DEBUG_IMAGE(imageProcessorGoals);
00137
00138
00139 const Image& image;
00140
00141
00142 const CameraMatrix& cameraMatrix;
00143
00144
00145 const ColorTable& colorTable;
00146
00147 int goalIndicationAboveHorizon;
00148 int goalIndicationBelowHorizon;
00149 bool useFixedScanLines;
00150
00151
00152 ObstaclesPercept& obstaclesPercept;
00153
00154
00155 LandmarksPercept& landmarksPercept;
00156
00157
00158 colorClass colorOfOpponentGoal;
00159
00160
00161 colorClass colorOfOwnGoal;
00162
00163
00164 Geometry::Line horizonLine, verticalLine;
00165
00166
00167 int numberOfHorizontalScanLines;
00168
00169 enum{maxNumberOfHorizontalScanLines = 32};
00170 enum{maxNumberOfGoalScanLines = 255};
00171
00172
00173 Vector2<int> leftPoint[maxNumberOfHorizontalScanLines];
00174
00175
00176 Vector2<int> rightPoint[maxNumberOfHorizontalScanLines];
00177
00178
00179 int numberOfGoalIndications;
00180
00181
00182 Vector2<int> goalIndicationLeft[maxNumberOfGoalScanLines];
00183
00184
00185 Vector2<int> goalIndicationCenter[maxNumberOfGoalScanLines];
00186
00187
00188 Vector2<int> goalIndicationRight[maxNumberOfGoalScanLines];
00189
00190
00191 bool leftOfGoalIndicationIsOnBorder[maxNumberOfGoalScanLines];
00192
00193
00194 bool rightOfGoalIndicationIsOnBorder[maxNumberOfGoalScanLines];
00195
00196
00197 colorClass colorOfGoalIndication[maxNumberOfGoalScanLines];
00198
00199
00200 int numberOfGoalScanLines;
00201
00202
00203 Vector2<int> topGoalPoint[maxNumberOfGoalScanLines];
00204
00205
00206 Vector2<int> bottomGoalPoint[maxNumberOfGoalScanLines];
00207
00208 bool scanLineToCheckBestAngle[maxNumberOfGoalScanLines];
00209
00210
00211 int indexOfGoalIndication[maxNumberOfGoalScanLines];
00212
00213
00214 colorClass colorOfGoalScanLine[maxNumberOfGoalScanLines];
00215
00216 };
00217
00218 #endif
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267