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

Modules/ImageProcessor/VLCImageProcessor/VLCLineFinder_DeterministicApproach.h

Go to the documentation of this file.
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   * Add a new LinePont for later consideration.
00024   * @param pointOnLine Image coordinates of the point.
00025   * @param normalToLine Normal vector to the line (indicated by the gradient).
00026   */ 
00027   void considerLinePoint(
00028     Vector2<int> & pointOnLine,
00029     Vector2<double> & normalToLine);
00030       
00031   /**
00032   * Calculates lines and crossings out of the given LinePoints.
00033   * @param linesPercept The LinesPercept, where the found information is stored.
00034   * @param cameraMatrix The CameraMatrix.
00035   * @param image The Image.
00036   * @param imageInfo The ImageInfo.
00037   * @param robotPose The RobotPose.
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   * Calculates lines and crossings out of the given LinePoints considering given information about the center circle.
00048   * @param linesPercept The LinesPercept, where the found information is stored.
00049   * @param cameraMatrix The CameraMatrix.
00050   * @param image The Image.
00051   * @param imageInfo The ImageInfo.
00052   * @param robotPose The RobotPose.
00053   * @param circleFound True if the circle was found.
00054   * @param circleOnField The Coordinates of the center circle on the field relative to the robot.
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   * Resets the lineFinder.
00067   */
00068   void reset();
00069   
00070     
00071   /**
00072   * Returns the number of found lines.
00073   */
00074   int getNumberOfLines();
00075     
00076   /**
00077   * Returns the line by number.
00078   * @param number The number of the line to return.
00079   * @param pointOnLine The base of the line.
00080   * @param normalToLine The normal of the line.
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   // for VLC
00091   void setBestColorTable(ColorTable * newBestColorTable)
00092   {
00093     bestColorTable = newBestColorTable;
00094   }
00095   //
00096 
00097   
00098 private:
00099   /**
00100   * Calculates line fragments out of the given LinePoints.
00101   */ 
00102   void findLineFragments();
00103   
00104   /**
00105   * Calculates lines out of the previously calculated line fragments.
00106   * @param linesPercept The LinesPercept.
00107   * @param cameraMatrix The CameraMatrix.
00108   * @param image The Image.
00109   * @param imageInfo The ImageInfo.
00110   */ 
00111   void findLines(
00112     LinesPercept & linesPercept,
00113     const CameraMatrix& cameraMatrix,
00114     const Image& image,
00115     const ImageInfo& imageInfo);
00116     
00117   /**
00118   * Calculates crossings out of the previously calculated lines.
00119   * @param linesPercept The LinesPercept.
00120   * @param cameraMatrix The CameraMatrix.
00121   * @param image The Image.
00122   * @param robotPose The RobotPose.
00123   * @param imageInfo The ImageInfo.
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   * Adds the crossing to the linesPercept including some characteristics found by additional scanning.
00134   * @param intersectionInImage The intersection in the image.
00135   * @param intersectionOnField The intersection on the field.
00136   * @param int The first line involved in this crossing.
00137   * @param int The second line involved in this crossing.
00138   * @param linesPercept The LinesPercept.
00139   * @param image The Image.
00140   * @param imageInfo The ImageInfo.
00141   * @param cameraMatrix The CameraMatrix.
00142   * @param robotPose The RobotPose.
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   * Filters out some line fragments, that may be caused by a center circle.
00157   * Do only use when no center detection available.
00158   * @param cameraMatrix The CameraMatrix.
00159   * @param image The Image.
00160   * @param robotPose The RobotPose.
00161   * @return true if circle found.
00162   */ 
00163   bool handleCenterCircle(
00164     const CameraMatrix& cameraMatrix,
00165     const Image& image,
00166     const RobotPose & robotPose);
00167 
00168   /**
00169   * Filters out line points belonging to the center circle.
00170   * @param centerOnField The centerCircle found by the circleFinder.
00171   * @param cameraMatrix The CameraMatrix.
00172   * @param image The Image.
00173   * @return true.
00174   */ 
00175   bool handleCenterCircle(
00176     const Vector2<double> & centerOnField,
00177     const CameraMatrix& cameraMatrix,
00178     const Image& image);
00179 
00180   /**
00181   * Writes the centerCircle (if found by one of the attempts) to the LinesPercept.
00182   * @param linesPercept The LinesPercept.
00183   * @param cameraMatrix The CameraMatrix.
00184   * @param image The Image.
00185   */ 
00186   void addCenterCirclePercept(
00187     LinesPercept & linesPercept,
00188     const CameraMatrix& cameraMatrix,
00189     const Image& image);
00190 
00191   /**
00192   * Very rough calculation if lines are perpendicular on the field (used for validating crossings).
00193   * @param lineNumber1 Number of the 1st line.
00194   * @param lineNumber2 Number of the 2nd line.
00195   * @param cameraMatrix The CameraMatrix.
00196   * @param image The Image.
00197   * @return True if the lines are perpendicular.
00198   */ 
00199   bool linesPerpendicularOnField(
00200     int lineNumber1,
00201     int lineNumber2,
00202     const CameraMatrix& cameraMatrix,
00203     const Image& image);
00204 
00205   /**
00206   * Calculates the projected line on the field.
00207   * @param lineNumber Number of the line to be projected on the field.
00208   * @param base The resulting base.
00209   * @param direction The resulting direction.
00210   * @param cameraMatrix The CameraMatrix.
00211   * @param image The Image.
00212   * @return true if calculation was successful.
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   * Calculates the projected line on the field.
00223   * @param baseInImage The base in the image.
00224   * @param directionInImage The direction in the image.
00225   * @param baseOnField The resulting base.
00226   * @param directionOnField The resulting direction.
00227   * @param cameraMatrix The CameraMatrix.
00228   * @param image The Image.
00229   * @return true if calculation was successful.
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   * Calculates the projected line on the field.
00241   * @param crossingPoint The crossingPoint in the image.
00242   * @param directionToScanAt The direction in the image, on which side of the crossingPoint should be scanned.
00243   * @param scanningDirection The direction of the scan line (not always perpendicular because of perspectival distortion).
00244   * @param lineSize The size of a line at this position in the image.
00245   * @param result The result of the scan.
00246   * @param cameraMatrix The CameraMatrix.
00247   * @param image The Image.
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   * Verifies if the found circle really is one.
00260   * @param circleOnFieldRelative The coordinates of the circle on the field.
00261   * @param orientation The orientation of the middle line through the circle.
00262   * @param cameraMatrix The CameraMatrix.
00263   * @param image The Image.
00264   * @return true if nothing is found that proves the candidate not to be a circle.
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   // for the resulting lines (fused from line fragmens)
00292   int numberOfLines;
00293   //LineFragment lines[maxNumberOfLines];
00294   LineFragment * lines;
00295   //
00296 
00297 
00298   // for line fragments
00299   int numberOfLineFragments;
00300   bool lineFragmentAlreadyConsidered[maxNumberOfLines*2];
00301   //LineFragment lineFragments[maxNumberOfLines*2];
00302   LineFragment * lineFragments;
00303   //
00304 
00305   // for the centerCircle
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; // used for fusing parallel line fragments, that are nearly perpendicular to the horizon
00324 
00325   
00326   // for VLC
00327   ColorTable * bestColorTable;
00328   //
00329 };
00330 
00331 
00332 #endif // __VLCLineFinder_DeterministicApproach_h_
00333 

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