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

Modules/ImageProcessor/SlamImageProcessor/SlamImageProcessor.h

Go to the documentation of this file.
00001 /**
00002 * @file SlamImageProcessor.h
00003 *
00004 * Definition of class SlamImageProcessor
00005 *
00006 * @author <a href="mailto:juengel@informatik.hu-berlin.de">Matthias Juengel</a>
00007 * @author <a href="mailto:roefer@tzi.de">Thomas Röfer</a>
00008 */
00009 
00010 #ifndef __SlamImageProcessor_h_
00011 #define __SlamImageProcessor_h_
00012 
00013 // Include those first to get the right macros
00014 #include "../GT2005ImageProcessor/GT2005BallSpecialist.h"
00015 #include "../GT2005ImageProcessor/GT2005Clustering.h"
00016 #include "../GT2005ImageProcessor/GT2005LineFinder_DeterministicApproach.h"
00017 //#include "../MSHImageProcessor/MSHCenterCircleFinder.h"
00018 
00019 #include "Modules/ImageProcessor/ImageProcessor.h"
00020 #include "Tools/Debugging/DebugDrawings.h"
00021 #include "Tools/Math/Geometry.h"
00022 #include "Tools/Debugging/DebugImages.h"
00023 #include "Tools/RingBuffer.h"
00024 #include "Modules/ImageProcessor/ImageProcessorTools/ColorCorrector.h"
00025 #include "SlamImageProcessorTools.h"
00026 #include "SlamGoalRecognizer.h"
00027 #include "SlamBeaconDetector.h"
00028 #include "SlamEdgeSpecialist.h"
00029 #include "SlamBorderFinder.h"
00030 #include "Tools/Actorics/RobotDimensions.h"
00031 #include "Tools/RobotConfiguration.h"
00032 #include "Tools/Math/Common.h"
00033 
00034 struct PinkCaracteristic
00035 {
00036   double  pixel;
00037   int   count;
00038 };
00039 
00040 #define NUM_PINK  16
00041 
00042 /**
00043 * @class SlamImageProcessor
00044 *
00045 * The lines image processor recognizes characteristic lines in the image.
00046 * Four types of lines are distinguished:
00047 * edges between the skyblue goal and the field, edges between the yellow goal 
00048 * and the field, edges between the border and the field, and edges between the
00049 * field lines and the field.
00050 *
00051 * The module scans vertical and horizontal lines in the image from top to bottom
00052 * and from left to right. As the green of the field is very dark, all edges are
00053 * characterized by a big difference of the y-channel of adjacent pixels. An
00054 * increase in the y-channel followed by a decrease is an indication for an edge.
00055 *
00056 * The projection of the pixels on the field plane is used to determine their
00057 * relative position to the robot.
00058 *
00059 * @author <a href="mailto:juengel@informatik.hu-berlin.de">Matthias Juengel</a>
00060 * @author <a href="mailto:roefer@tzi.de">Thomas Röfer</a>
00061 */ 
00062 class SlamImageProcessor : public ImageProcessor
00063 {
00064 public:
00065   /** 
00066   * Constructor.
00067   * @param interfaces The paramters of the SlamImageProcessor module.
00068   */
00069   SlamImageProcessor(const ImageProcessorInterfaces& interfaces);
00070 
00071   /** Executes the module */
00072   virtual void execute();
00073 
00074   /** Handles an incoming message
00075   * @param message The message
00076   */
00077   virtual bool handleMessage(InMessage& message);
00078 
00079 private:
00080   PinkCaracteristic pinkCaracteristic[NUM_PINK];
00081 
00082   double filterWeight;
00083 
00084   double averageY;
00085   double averageU;
00086   double averageV;
00087 
00088   int averageCount;
00089 
00090   double xFactor, /**< Factor to convert the pixel coordinate space to the anglular coordinate space. */
00091          yFactor; /**< Factor to convert the pixel coordinate space to the anglular coordinate space. */
00092   int yThreshold; /**< Brightness increase threshold. */
00093   int vThreshold; /**< Brightness decrease threshold. */
00094   int orangeCount,  /**< Number of columns with ball points. */
00095       noOrangeCount, /**< Number of columns without a ball point. */
00096       noRedCount, /**< Number of columns without a red robot point. */
00097       noBlueCount, /**< Number of columns without a blue robot point. */
00098       noGoalCount, /**< Number of columns without a opponent goal seen. */
00099       closestBottom; /**< Closest bottom point on the grid. */
00100   Vector2<int> firstRed, /**< First red robot point in a cluster. */
00101                closestRed, /**< Closest red robot point in a cluster. */
00102                lastRed, /**< Last red robot point in a cluster. */
00103                firstBlue, /**< First blue robot point in a cluster. */
00104                closestBlue, /**< Closest blue robot point in a cluster. */
00105                lastBlue, /**< Last blue robot point in a cluster. */
00106                firstFlag, /**< First flag point in a cluster. */
00107                lastFlag; /**< Last flag point in a cluster. */
00108   bool goalAtBorder; /**< Is the first goal point at the image border? */
00109   int longestBallRun;
00110   Vector2<int> ballCandidate;
00111   GT2005Clustering ballClustering;
00112   GT2005LineFinder_DeterministicApproach lineFinder;
00113 //  MSHCenterCircleFinder circleFinder;
00114 
00115   ImageInfo imageInfo; /**< Additional information about the current image */
00116 
00117   CameraMatrix cmTricot, /**< Camera matrix without tricot height. */
00118                prevCmTricot; /**< The tricot matrix of the previous image. */
00119 
00120   ColorCorrector colorCorrector; /**< The color correction tool. */
00121 
00122   SlamBeaconDetector beaconDetector; /**< The beacon detector */
00123 
00124   SlamGoalRecognizer goalRecognizer; /**< The goal recognizer. */
00125 
00126   GT2005BallSpecialist ballSpecialist; /**< The ball specialist. */
00127 
00128   SlamEdgeSpecialist edgeSpecialist; /**< The edge specialist. */
00129 
00130   SlamBorderFinder borderFinder;
00131 
00132 
00133   int count;
00134 
00135   /**
00136   * The function scans columns for line points.
00137   */
00138   void scanColumns();
00139 
00140   /** 
00141   * The function scans rows for line points. 
00142   */
00143   void scanRows();
00144 
00145   /** 
00146   * The function scans a line for line points. 
00147   * @param start The start point of the line.
00148   * @param end The end point of the line.
00149   * @param vertical Vertical lines are scanned for more information.
00150   * @param noLines Should the line not be scanned for points on field lines or borders?
00151   */
00152   void scan(const Vector2<int>& start, const Vector2<int>& end,
00153             bool vertical, bool noLines);
00154   
00155   /** 
00156   * The function clusters points of red and blue robots.
00157   * @param bottomPoint The bottom point of the current scan column.
00158   * @param redFound Has a red robot point been found? In that case, the last
00159   *                 entry in the lines percept is that point.
00160   * @param blueFound Has a blue robot point been found? In that case, the last
00161   *                  entry in the lines percept is that point.
00162   */
00163   void clusterRobots(const unsigned char* bottomPoint, bool redFound, bool blueFound);
00164 
00165   /** 
00166   * The function clusters flag points.
00167   * @param flagType The type of the flag.
00168   * @param point The center of the pink area.
00169   */
00170   //void clusterFlags(Flag::FlagType flagType, const Vector2<int>& point);
00171 
00172   /**
00173   * The function filters the percepts, i.e. it removes potential misreadings.
00174   */
00175   void filterPercepts();
00176 
00177   /**
00178   * The function filters the line-percepts, i.e. it removes potential misreadings, for the given line-type.
00179   */
00180   void filterLinesPercept(LinesPercept& percept, int type, const CameraMatrix& cameraMatrix, const CameraMatrix& prevCameraMatrix, const Image& image);
00181 
00182   /**
00183    * The function calculates the angle of an edge at an edge point.
00184    * @param angleInImage The angle in image coordinates to be determined.
00185    * @param angleOnField The angle in relative robot field coordinates to be determined.
00186    * @param pointInImage The edge point in image coordinates.
00187    * @param pointOnField The edge point in field coordinates.
00188    * @param scanAngle The angle of the scan line the point was found on.
00189    * @param pixelBuffer The pixels on the scan line around the edge point.
00190    * @param againstScanline The flag if bright to dark is detected against the direction of the scanline.
00191    * @param borderOrLine The flag if this edge belongs to a border or a line (white to green edge).
00192    * @param channel The channel the gradient is calculated in.
00193    * @return Whether the angle in field coordinates could be determined
00194    */
00195   bool calcEdgeAngle(
00196     double& angleInImage,
00197     double& angleOnField,
00198     const Vector2<int>& pointInImage, 
00199     const Vector2<int>& pointOnField,
00200     double scanAngle,
00201     const RingBuffer<const unsigned char*,7>& pixelBuffer,
00202     const bool againstScanline = false,
00203     const bool borderOrLine = true,
00204     int channel = 0);
00205 
00206  /** 
00207   * The function converts an address to pixel coordinates.
00208   * @param p An address in image.image.
00209   * @return The x- and y-coordinates of the corresponding pixel.
00210   */
00211   Vector2<int> getCoords(const unsigned char* p) const
00212   {
00213     const int diff(p - &image.image[0][0][0]);
00214     return Vector2<int>(diff % cameraResolutionWidth_ERS7, diff / (cameraResolutionWidth_ERS7 * 6));
00215   }
00216 
00217   //!@name Helpers for grid drawing
00218   //!@{
00219   const unsigned char* last;
00220   Drawings::Color lineColor;
00221   void plot(const unsigned char* p,Drawings::Color color);
00222   //!@}
00223 
00224   double angleBetweenDirectionOfViewAndGround;
00225 
00226   int numberOfScannedPixels;
00227   bool prevCameraMatrixUninitialized;
00228 
00229   Matrix2x2<double> rotation2x2;
00230 
00231   DECLARE_DEBUG_IMAGE(imageProcessorPlayers);
00232   DECLARE_DEBUG_IMAGE(imageProcessorGeneral);
00233   DECLARE_DEBUG_COLOR_CLASS_IMAGE(segmentedImage1);
00234   DECLARE_DEBUG_IMAGE(imageProcessorBall);
00235   DECLARE_DEBUG_IMAGE(imageProcessorGradients);
00236 
00237   N_DECLARE_DEBUG_IMAGE(colorCorrected);
00238   N_DECLARE_DEBUG_IMAGE(colorCorrectedAsJpeg);
00239   N_DECLARE_DEBUG_COLOR_CLASS_IMAGE(segmented);
00240   N_DECLARE_DEBUG_IMAGE(ball);
00241   N_DECLARE_DEBUG_IMAGE(edgeDetection);
00242   N_DECLARE_DEBUG_GRAY_SCALE_IMAGE(scanLines);
00243 };
00244 
00245 #endif// __SlamImageProcessor_h_

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