00001 #ifndef __VLCLineFinder_DeterministicApproach_h_
00002 #define __VLCLineFinder_DeterministicApproach_h_
00003
00004
00005 #include "Representations/Perception/Image.h"
00006 #include "Representations/Perception/LinesPercept.h"
00007 #include "Tools/Math/Geometry.h"
00008 #include "Tools/Math/Matrix2x2.h"
00009 #include "VLCImageProcessorTools.h"
00010 #include "Modules/ImageProcessor/ImageProcessorTools/ImageProcessorUtilityClasses.h"
00011 #include "Tools/Math/Common.h"
00012 #include "Modules/ImageProcessor/ImageProcessorTools/BresenhamLineScan.h"
00013 #include "Tools/ColorClasses.h"
00014
00015
00016 class VLCLineFinder_DeterministicApproach
00017 {
00018 public:
00019 VLCLineFinder_DeterministicApproach(const ColorCorrector& colorCorrector, const ColorTable& colorTable);
00020 ~VLCLineFinder_DeterministicApproach(void);
00021
00022
00023
00024
00025
00026
00027 void considerLinePoint(
00028 Vector2<int> & pointOnLine,
00029 Vector2<double> & normalToLine);
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 void execute(
00040 LinesPercept & linesPercept,
00041 const CameraMatrix& cameraMatrix,
00042 const Image& image,
00043 const ImageInfo& imageInfo,
00044 const RobotPose & robotPose);
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056 void execute(
00057 LinesPercept & linesPercept,
00058 const CameraMatrix& cameraMatrix,
00059 const Image& image,
00060 const ImageInfo& imageInfo,
00061 const RobotPose & robotPose,
00062 const bool circleFound,
00063 const Vector2<double> & circleOnField);
00064
00065
00066
00067
00068 void reset();
00069
00070
00071
00072
00073
00074 int getNumberOfLines();
00075
00076
00077
00078
00079
00080
00081
00082 void getLine(
00083 int number,
00084 Vector2<int> & pointOnLine,
00085 Vector2<double> & normalToLine);
00086
00087 enum {maxNumberOfLines = 6, maxNumberOfLinePoints = 60, pointsNeededForLine = 3};
00088
00089
00090
00091 void setBestColorTable(ColorTable * newBestColorTable)
00092 {
00093 bestColorTable = newBestColorTable;
00094 }
00095
00096
00097
00098 private:
00099
00100
00101
00102 void findLineFragments();
00103
00104
00105
00106
00107
00108
00109
00110
00111 void findLines(
00112 LinesPercept & linesPercept,
00113 const CameraMatrix& cameraMatrix,
00114 const Image& image,
00115 const ImageInfo& imageInfo);
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125 void findIntersections(
00126 LinesPercept & linesPercept,
00127 const CameraMatrix& cameraMatrix,
00128 const Image& image,
00129 const RobotPose & robotPose,
00130 const ImageInfo& imageInfo);
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144 void addCrossingsPercept(
00145 const Vector2<double> & intersectionInImage,
00146 const Vector2<int> & intersectionOnField,
00147 int lineNumber1,
00148 int lineNumber2,
00149 LinesPercept & linesPercept,
00150 const Image& image,
00151 const ImageInfo& imageInfo,
00152 const CameraMatrix & cameraMatrix,
00153 const RobotPose & robotPose);
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 bool handleCenterCircle(
00164 const CameraMatrix& cameraMatrix,
00165 const Image& image,
00166 const RobotPose & robotPose);
00167
00168
00169
00170
00171
00172
00173
00174
00175 bool handleCenterCircle(
00176 const Vector2<double> & centerOnField,
00177 const CameraMatrix& cameraMatrix,
00178 const Image& image);
00179
00180
00181
00182
00183
00184
00185
00186 void addCenterCirclePercept(
00187 LinesPercept & linesPercept,
00188 const CameraMatrix& cameraMatrix,
00189 const Image& image);
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 bool linesPerpendicularOnField(
00200 int lineNumber1,
00201 int lineNumber2,
00202 const CameraMatrix& cameraMatrix,
00203 const Image& image);
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 bool calculateLineOnField(
00215 int lineNumber,
00216 Vector2<double> & base,
00217 Vector2<double> & direction,
00218 const CameraMatrix& cameraMatrix,
00219 const Image& image);
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231 bool calculateLineOnField(
00232 const Vector2<int> & baseInImage,
00233 const Vector2<double> & directionInImage,
00234 Vector2<double> & baseOnField,
00235 Vector2<double> & directionOnField,
00236 const CameraMatrix& cameraMatrix,
00237 const Image& image);
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249 void doVerificationScan(
00250 const Vector2<double> & crossingPoint,
00251 const Vector2<double> & directionToScanAt,
00252 const Vector2<double> & scanningDirection,
00253 int lineSize,
00254 LinesPercept::CrossingCharacteristic & result,
00255 const CameraMatrix& cameraMatrix,
00256 const Image& image);
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266 bool doVerificationScanForCircle(
00267 const Vector2<int> & circleOnFieldRelative,
00268 double orientation,
00269 const CameraMatrix& cameraMatrix,
00270 const Image& image);
00271
00272 struct LinePoint
00273 {
00274 Vector2<int> pointOnLine;
00275 Vector2<double> normalToLine;
00276 int belongsToLineNo;
00277 };
00278
00279 struct LineFragment
00280 {
00281 Vector2<int> base;
00282 Vector2<double> normal;
00283 bool lineFragmentAlreadyConsidered;
00284 Vector2<int> start;
00285 Vector2<int> end;
00286 double averageStep;
00287 int numberOfPoints;
00288 };
00289
00290
00291
00292 int numberOfLines;
00293
00294 LineFragment * lines;
00295
00296
00297
00298
00299 int numberOfLineFragments;
00300 bool lineFragmentAlreadyConsidered[maxNumberOfLines*2];
00301
00302 LineFragment * lineFragments;
00303
00304
00305
00306 Vector2<int> fromCircleFinder;
00307 bool foundByCircleFinder;
00308 Vector2<int> fromOwnHandling;
00309 bool foundByOwnHandling;
00310 double centerCircleOrientation;
00311 Vector2<double> lastSeenCircleGlobal;
00312 double lastSeenCircleOrientationGlobal;
00313 int framesSinceLastSeen;
00314 int frameCount, circleCount;
00315
00316
00317 const ColorCorrector& colorCorrector;
00318 const ColorTable& colorTable;
00319 LinePoint linePoints[maxNumberOfLinePoints];
00320 int numberOfLinePoints;
00321 double normDistance;
00322 double normProjection;
00323 double normProjectionPerpendicularToHorizon;
00324
00325
00326
00327 ColorTable * bestColorTable;
00328
00329 };
00330
00331
00332 #endif // __VLCLineFinder_DeterministicApproach_h_
00333