Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Modules/ImageProcessor/SlamImageProcessor/SlamBorderFinder.h

Go to the documentation of this file.
00001 /**
00002 * @file SlamBorderFinder.h
00003 *
00004 * Definition of class SlamBorderFinder
00005 *
00006 * @author <a href="mailto:stefan.czarnetzki@uni-dortmund.de">Stefan Czarnetzki</a>
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   * Add a new LinePont for later consideration.
00032   * @param pointOnLine Image coordinates of the point.
00033   * @param normalToLine Normal vector to the line (indicated by the gradient).
00034   */ 
00035   void considerLinePoint(
00036     Vector2<int> & pointOnLine,
00037     Vector2<double> & normalToLine);
00038       
00039   /**
00040   * Calculates lines and crossings out of the given LinePoints.
00041   * @param linesPercept The LinesPercept, where the found information is stored.
00042   * @param cameraMatrix The CameraMatrix.
00043   * @param image The Image.
00044   * @param imageInfo The ImageInfo.
00045   * @param robotPose The RobotPose.
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   * Resets the lineFinder.
00056   */
00057   void reset();
00058   
00059     
00060   /**
00061   * Returns the number of found lines.
00062   */
00063   int getNumberOfLines();
00064     
00065   /**
00066   * Returns the line by number.
00067   * @param number The number of the line to return.
00068   * @param pointOnLine The base of the line.
00069   * @param normalToLine The normal of the line.
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   * Calculates line fragments out of the given LinePoints.
00081   */ 
00082   void findLineFragments();
00083   
00084   /**
00085   * Calculates lines out of the previously calculated line fragments.
00086   * @param linesPercept The LinesPercept.
00087   * @param cameraMatrix The CameraMatrix.
00088   * @param image The Image.
00089   * @param imageInfo The ImageInfo.
00090   */ 
00091   void findLines(
00092     LinesPercept & linesPercept,
00093     const CameraMatrix& cameraMatrix,
00094     const Image& image,
00095     const ImageInfo& imageInfo);
00096     
00097   /**
00098   * Calculates crossings out of the previously calculated lines.
00099   * @param linesPercept The LinesPercept.
00100   * @param cameraMatrix The CameraMatrix.
00101   * @param image The Image.
00102   * @param robotPose The RobotPose.
00103   * @param imageInfo The ImageInfo.
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   * Adds the crossing to the linesPercept including some characteristics found by additional scanning.
00114   * @param intersectionInImage The intersection in the image.
00115   * @param intersectionOnField The intersection on the field.
00116   * @param int The first line involved in this crossing.
00117   * @param int The second line involved in this crossing.
00118   * @param linesPercept The LinesPercept.
00119   * @param image The Image.
00120   * @param imageInfo The ImageInfo.
00121   * @param cameraMatrix The CameraMatrix.
00122   * @param robotPose The RobotPose.
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   * Calculates the direction away from the border.
00137   * @param linesPercept The LinesPercept.
00138   * @param image The Image.
00139   * @param imageInfo The ImageInfo.
00140   * @param cameraMatrix The CameraMatrix.
00141   * @param robotPose The RobotPose.
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   * Very rough calculation if lines are perpendicular on the field (used for validating crossings).
00152   * @param lineNumber1 Number of the 1st line.
00153   * @param lineNumber2 Number of the 2nd line.
00154   * @param cameraMatrix The CameraMatrix.
00155   * @param image The Image.
00156   * @return True if the lines are perpendicular.
00157   */ 
00158   bool linesPerpendicularOnField(
00159     int lineNumber1,
00160     int lineNumber2,
00161     const CameraMatrix& cameraMatrix,
00162     const Image& image);
00163 
00164   /**
00165   * Calculates the projected line on the field.
00166   * @param lineNumber Number of the line to be projected on the field.
00167   * @param base The resulting base.
00168   * @param direction The resulting direction.
00169   * @param cameraMatrix The CameraMatrix.
00170   * @param image The Image.
00171   * @return true if calculation was successful.
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   * Calculates the projected line on the field.
00182   * @param baseInImage The base in the image.
00183   * @param directionInImage The direction in the image.
00184   * @param baseOnField The resulting base.
00185   * @param directionOnField The resulting direction.
00186   * @param cameraMatrix The CameraMatrix.
00187   * @param image The Image.
00188   * @return true if calculation was successful.
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   * Calculates the projected line on the field.
00200   * @param crossingPoint The crossingPoint in the image.
00201   * @param directionToScanAt The direction in the image, on which side of the crossingPoint should be scanned.
00202   * @param scanningDirection The direction of the scan line (not always perpendicular because of perspectival distortion).
00203   * @param lineSize The size of a line at this position in the image.
00204   * @param result The result of the scan.
00205   * @param cameraMatrix The CameraMatrix.
00206   * @param image The Image.
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   // for the resulting lines (fused from line fragmens)
00237   int numberOfLines;
00238   //LineFragment lines[maxNumberOfLines];
00239   LineFragment * lines;
00240   //
00241 
00242 
00243   // for line fragments
00244   int numberOfLineFragments;
00245   bool lineFragmentAlreadyConsidered[maxNumberOfLines*2];
00246   //LineFragment lineFragments[maxNumberOfLines*2];
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; // used for fusing parallel line fragments, that are nearly perpendicular to the horizon
00257 };
00258 
00259 
00260 #endif // __SlamBorderFinder_h_
00261 

Generated on Mon Mar 20 21:59:51 2006 for GT2005 by doxygen 1.3.6