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

Modules/ImageProcessor/GT2005ImageProcessor/GT2005LineFinder_DeterministicApproach.h

Go to the documentation of this file.
00001 /**
00002 * @file GT2005LineFinder_DeterministicApproach.h
00003 *
00004 * Definition of class GT2005LineFinder_DeterministicApproach
00005 *
00006 * @author <a href="mailto:stefan.czarnetzki@uni-dortmund.de">Stefan Czarnetzki</a>
00007 */
00008 
00009 #ifndef __GT2005LineFinder_DeterministicApproach_h_
00010 #define __GT2005LineFinder_DeterministicApproach_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 "GT2005ImageProcessorTools.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 GT2005LineFinder_DeterministicApproach
00025 {
00026 public:
00027   GT2005LineFinder_DeterministicApproach(const ColorCorrector& colorCorrector, const ColorTable& colorTable);
00028   ~GT2005LineFinder_DeterministicApproach(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   * Calculates lines and crossings out of the given LinePoints considering given information about the center circle.
00056   * @param linesPercept The LinesPercept, where the found information is stored.
00057   * @param cameraMatrix The CameraMatrix.
00058   * @param image The Image.
00059   * @param imageInfo The ImageInfo.
00060   * @param robotPose The RobotPose.
00061   * @param circleFound True if the circle was found.
00062   * @param circleOnField The Coordinates of the center circle on the field relative to the robot.
00063   */ 
00064   void execute(
00065     LinesPercept & linesPercept,
00066     const CameraMatrix& cameraMatrix,
00067     const Image& image,
00068     const ImageInfo& imageInfo,
00069     const RobotPose & robotPose,
00070     const bool circleFound,
00071     const Vector2<double> & circleOnField);
00072 
00073   /**
00074   * Resets the lineFinder.
00075   */
00076   void reset();
00077   
00078     
00079   /**
00080   * Returns the number of found lines.
00081   */
00082   int getNumberOfLines();
00083     
00084   /**
00085   * Returns the line by number.
00086   * @param number The number of the line to return.
00087   * @param pointOnLine The base of the line.
00088   * @param normalToLine The normal of the line.
00089   */
00090   void getLine(
00091     int number,
00092     Vector2<int> & pointOnLine,
00093     Vector2<double> & normalToLine);
00094   
00095   enum {maxNumberOfLines = 6, maxNumberOfLinePoints = 60, pointsNeededForLine = 3};
00096   
00097 private:
00098   /**
00099   * Calculates line fragments out of the given LinePoints.
00100   */ 
00101   void findLineFragments();
00102   
00103   /**
00104   * Calculates lines out of the previously calculated line fragments.
00105   * @param linesPercept The LinesPercept.
00106   * @param cameraMatrix The CameraMatrix.
00107   * @param image The Image.
00108   * @param imageInfo The ImageInfo.
00109   */ 
00110   void findLines(
00111     LinesPercept & linesPercept,
00112     const CameraMatrix& cameraMatrix,
00113     const Image& image,
00114     const ImageInfo& imageInfo);
00115     
00116   /**
00117   * Calculates crossings out of the previously calculated lines.
00118   * @param linesPercept The LinesPercept.
00119   * @param cameraMatrix The CameraMatrix.
00120   * @param image The Image.
00121   * @param robotPose The RobotPose.
00122   * @param imageInfo The ImageInfo.
00123   */
00124   void findIntersections(
00125     LinesPercept & linesPercept,
00126     const CameraMatrix& cameraMatrix,
00127     const Image& image,
00128     const RobotPose & robotPose,
00129     const ImageInfo& imageInfo);
00130 
00131     /**
00132   * Adds the crossing to the linesPercept including some characteristics found by additional scanning.
00133   * @param intersectionInImage The intersection in the image.
00134   * @param intersectionOnField The intersection on the field.
00135   * @param int The first line involved in this crossing.
00136   * @param int The second line involved in this crossing.
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 addCrossingsPercept(
00144     const Vector2<double> & intersectionInImage,
00145     const Vector2<int> & intersectionOnField, 
00146     int lineNumber1,
00147     int lineNumber2,
00148     LinesPercept & linesPercept,
00149     const Image& image,
00150     const ImageInfo& imageInfo,
00151     const CameraMatrix & cameraMatrix,
00152     const RobotPose & robotPose);
00153 
00154   /**
00155   * Filters out some line fragments, that may be caused by a center circle.
00156   * Do only use when no center detection available.
00157   * @param cameraMatrix The CameraMatrix.
00158   * @param image The Image.
00159   * @param robotPose The RobotPose.
00160   * @return true if circle found.
00161   */ 
00162   bool handleCenterCircle(
00163     const CameraMatrix& cameraMatrix,
00164     const Image& image,
00165     const RobotPose & robotPose);
00166 
00167   /**
00168   * Filters out line points belonging to the center circle.
00169   * @param centerOnField The centerCircle found by the circleFinder.
00170   * @param cameraMatrix The CameraMatrix.
00171   * @param image The Image.
00172   * @return true.
00173   */ 
00174   bool handleCenterCircle(
00175     const Vector2<double> & centerOnField,
00176     const CameraMatrix& cameraMatrix,
00177     const Image& image);
00178 
00179   /**
00180   * Writes the centerCircle (if found by one of the attempts) to the LinesPercept.
00181   * @param linesPercept The LinesPercept.
00182   * @param cameraMatrix The CameraMatrix.
00183   * @param image The Image.
00184   */ 
00185   void addCenterCirclePercept(
00186     LinesPercept & linesPercept,
00187     const CameraMatrix& cameraMatrix,
00188     const Image& image);
00189 
00190   /**
00191   * Very rough calculation if lines are perpendicular on the field (used for validating crossings).
00192   * @param lineNumber1 Number of the 1st line.
00193   * @param lineNumber2 Number of the 2nd line.
00194   * @param cameraMatrix The CameraMatrix.
00195   * @param image The Image.
00196   * @return True if the lines are perpendicular.
00197   */ 
00198   bool linesPerpendicularOnField(
00199     int lineNumber1,
00200     int lineNumber2,
00201     const CameraMatrix& cameraMatrix,
00202     const Image& image);
00203 
00204   /**
00205   * Calculates the projected line on the field.
00206   * @param lineNumber Number of the line to be projected on the field.
00207   * @param base The resulting base.
00208   * @param direction The resulting direction.
00209   * @param cameraMatrix The CameraMatrix.
00210   * @param image The Image.
00211   * @return true if calculation was successful.
00212   */ 
00213   bool calculateLineOnField(
00214     int lineNumber,
00215     Vector2<double> & base,
00216     Vector2<double> & direction,
00217     const CameraMatrix& cameraMatrix,
00218     const Image& image);
00219 
00220   /**
00221   * Calculates the projected line on the field.
00222   * @param baseInImage The base in the image.
00223   * @param directionInImage The direction in the image.
00224   * @param baseOnField The resulting base.
00225   * @param directionOnField The resulting direction.
00226   * @param cameraMatrix The CameraMatrix.
00227   * @param image The Image.
00228   * @return true if calculation was successful.
00229   */ 
00230   bool calculateLineOnField(
00231     const Vector2<int> & baseInImage,
00232     const Vector2<double> & directionInImage,
00233     Vector2<double> & baseOnField,
00234     Vector2<double> & directionOnField,
00235     const CameraMatrix& cameraMatrix,
00236     const Image& image);
00237   
00238   /**
00239   * Calculates the projected line on the field.
00240   * @param crossingPoint The crossingPoint in the image.
00241   * @param directionToScanAt The direction in the image, on which side of the crossingPoint should be scanned.
00242   * @param scanningDirection The direction of the scan line (not always perpendicular because of perspectival distortion).
00243   * @param lineSize The size of a line at this position in the image.
00244   * @param result The result of the scan.
00245   * @param cameraMatrix The CameraMatrix.
00246   * @param image The Image.
00247   */ 
00248   void doVerificationScan(
00249     const Vector2<double> & crossingPoint,
00250     const Vector2<double> & directionToScanAt,
00251     const Vector2<double> & scanningDirection,
00252     int lineSize,
00253     LinesPercept::CrossingCharacteristic & result,
00254     const CameraMatrix& cameraMatrix,
00255     const Image& image);
00256   
00257   /**
00258   * Verifies if the found circle really is one.
00259   * @param circleOnFieldRelative The coordinates of the circle on the field.
00260   * @param orientation The orientation of the middle line through the circle.
00261   * @param cameraMatrix The CameraMatrix.
00262   * @param image The Image.
00263   * @return true if nothing is found that proves the candidate not to be a circle.
00264   */ 
00265   bool doVerificationScanForCircle(
00266     const Vector2<int> & circleOnFieldRelative,
00267     double orientation,
00268     const CameraMatrix& cameraMatrix,
00269     const Image& image);
00270 
00271   struct LinePoint
00272   {
00273     Vector2<int> pointOnLine;
00274     Vector2<double> normalToLine;
00275     int belongsToLineNo;
00276   };
00277 
00278   struct LineFragment
00279   {
00280     Vector2<int> base;
00281     Vector2<double> normal;
00282     bool lineFragmentAlreadyConsidered;    
00283     Vector2<int> start;
00284     Vector2<int> end;
00285     double averageStep;
00286     int numberOfPoints;
00287   };
00288   
00289   
00290   // for the resulting lines (fused from line fragmens)
00291   int numberOfLines;
00292   //LineFragment lines[maxNumberOfLines];
00293   LineFragment * lines;
00294   //
00295 
00296 
00297   // for line fragments
00298   int numberOfLineFragments;
00299   bool lineFragmentAlreadyConsidered[maxNumberOfLines*2];
00300   //LineFragment lineFragments[maxNumberOfLines*2];
00301   LineFragment * lineFragments;
00302   //
00303 
00304   // for the centerCircle
00305   Vector2<int> fromCircleFinder;
00306   bool foundByCircleFinder;
00307   Vector2<int> fromOwnHandling;
00308   bool foundByOwnHandling;
00309   double centerCircleOrientation;
00310   Vector2<double> lastSeenCircleGlobal;
00311   double lastSeenCircleOrientationGlobal;
00312   int framesSinceLastSeen;
00313   int frameCount, circleCount;
00314   //
00315 
00316   const ColorCorrector& colorCorrector;
00317   const ColorTable& colorTable;
00318   LinePoint linePoints[maxNumberOfLinePoints];
00319   int numberOfLinePoints;
00320   double normDistance;
00321   double normProjection;
00322   double normProjectionPerpendicularToHorizon; // used for fusing parallel line fragments, that are nearly perpendicular to the horizon
00323 };
00324 
00325 
00326 #endif // __GT2005LineFinder_DeterministicApproach_h_
00327 

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