00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __SlamBorderFinder_h_
00010 #define __SlamBorderFinder_h_
00011
00012
00013 #include "Representations/Perception/Image.h"
00014 #include "Representations/Perception/LinesPercept.h"
00015 #include "Tools/Math/Geometry.h"
00016 #include "Tools/Math/Matrix2x2.h"
00017 #include "SlamImageProcessorTools.h"
00018 #include "Modules/ImageProcessor/ImageProcessorTools/ImageProcessorUtilityClasses.h"
00019 #include "Tools/Math/Common.h"
00020 #include "Modules/ImageProcessor/ImageProcessorTools/BresenhamLineScan.h"
00021 #include "Tools/ColorClasses.h"
00022
00023
00024 class SlamBorderFinder
00025 {
00026 public:
00027 SlamBorderFinder(const ColorCorrector& colorCorrector, const ColorTable& colorTable);
00028 ~SlamBorderFinder(void);
00029
00030
00031
00032
00033
00034
00035 void considerLinePoint(
00036 Vector2<int> & pointOnLine,
00037 Vector2<double> & normalToLine);
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 void execute(
00048 LinesPercept & linesPercept,
00049 const CameraMatrix& cameraMatrix,
00050 const Image& image,
00051 const ImageInfo& imageInfo,
00052 const RobotPose & robotPose);
00053
00054
00055
00056
00057 void reset();
00058
00059
00060
00061
00062
00063 int getNumberOfLines();
00064
00065
00066
00067
00068
00069
00070
00071 void getLine(
00072 int number,
00073 Vector2<int> & pointOnLine,
00074 Vector2<double> & normalToLine);
00075
00076 enum {maxNumberOfLines = 6, maxNumberOfLinePoints = 60, pointsNeededForLine = 3};
00077
00078 private:
00079
00080
00081
00082 void findLineFragments();
00083
00084
00085
00086
00087
00088
00089
00090
00091 void findLines(
00092 LinesPercept & linesPercept,
00093 const CameraMatrix& cameraMatrix,
00094 const Image& image,
00095 const ImageInfo& imageInfo);
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 void findIntersections(
00106 LinesPercept & linesPercept,
00107 const CameraMatrix& cameraMatrix,
00108 const Image& image,
00109 const RobotPose & robotPose,
00110 const ImageInfo& imageInfo);
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124 void addCrossingsPercept(
00125 const Vector2<double> & intersectionInImage,
00126 const Vector2<int> & intersectionOnField,
00127 int lineNumber1,
00128 int lineNumber2,
00129 LinesPercept & linesPercept,
00130 const Image& image,
00131 const ImageInfo& imageInfo,
00132 const CameraMatrix & cameraMatrix,
00133 const RobotPose & robotPose);
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143 void calculateDirectionAwayFromBorder(
00144 LinesPercept & linesPercept,
00145 const Image& image,
00146 const ImageInfo& imageInfo,
00147 const CameraMatrix & cameraMatrix,
00148 const RobotPose & robotPose);
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158 bool linesPerpendicularOnField(
00159 int lineNumber1,
00160 int lineNumber2,
00161 const CameraMatrix& cameraMatrix,
00162 const Image& image);
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173 bool calculateLineOnField(
00174 int lineNumber,
00175 Vector2<double> & base,
00176 Vector2<double> & direction,
00177 const CameraMatrix& cameraMatrix,
00178 const Image& image);
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190 bool calculateLineOnField(
00191 const Vector2<int> & baseInImage,
00192 const Vector2<double> & directionInImage,
00193 Vector2<double> & baseOnField,
00194 Vector2<double> & directionOnField,
00195 const CameraMatrix& cameraMatrix,
00196 const Image& image);
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 void doVerificationScan(
00209 const Vector2<double> & crossingPoint,
00210 const Vector2<double> & directionToScanAt,
00211 const Vector2<double> & scanningDirection,
00212 int lineSize,
00213 LinesPercept::CrossingCharacteristic & result,
00214 const CameraMatrix& cameraMatrix,
00215 const Image& image);
00216
00217 struct LinePoint
00218 {
00219 Vector2<int> pointOnLine;
00220 Vector2<double> normalToLine;
00221 int belongsToLineNo;
00222 };
00223
00224 struct LineFragment
00225 {
00226 Vector2<int> base;
00227 Vector2<double> normal;
00228 bool lineFragmentAlreadyConsidered;
00229 Vector2<int> start;
00230 Vector2<int> end;
00231 double averageStep;
00232 int numberOfPoints;
00233 };
00234
00235
00236
00237 int numberOfLines;
00238
00239 LineFragment * lines;
00240
00241
00242
00243
00244 int numberOfLineFragments;
00245 bool lineFragmentAlreadyConsidered[maxNumberOfLines*2];
00246
00247 LineFragment * lineFragments;
00248
00249
00250 const ColorCorrector& colorCorrector;
00251 const ColorTable& colorTable;
00252 LinePoint linePoints[maxNumberOfLinePoints];
00253 int numberOfLinePoints;
00254 double normDistance;
00255 double normProjection;
00256 double normProjectionPerpendicularToHorizon;
00257 };
00258
00259
00260 #endif // __SlamBorderFinder_h_
00261