00001 /** 00002 * @file GT2004ImageProcessor.h 00003 * 00004 * Definition of class GT2004ImageProcessor 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 __GT2004ImageProcessor_h_ 00011 #define __GT2004ImageProcessor_h_ 00012 00013 #include "Modules/ImageProcessor/ImageProcessor.h" 00014 #include "Tools/Debugging/DebugDrawings.h" 00015 #include "Tools/Math/Geometry.h" 00016 #include "Tools/Debugging/DebugImages.h" 00017 #include "Tools/RingBuffer.h" 00018 #include "Modules/ImageProcessor/ImageProcessorTools/ColorCorrector.h" 00019 #include "GT2004ImageProcessorTools.h" 00020 #include "GT2004GoalRecognizer.h" 00021 #include "GT2004BallSpecialist.h" 00022 #include "GT2004BeaconDetector.h" 00023 #include "GT2004EdgeSpecialist.h" 00024 #include "Tools/Actorics/RobotDimensions.h" 00025 #include "Tools/RobotConfiguration.h" 00026 #include "Tools/Math/Common.h" 00027 00028 /** 00029 * @class GT2004ImageProcessor 00030 * 00031 * The lines image processor recognizes characteristic lines in the image. 00032 * Four types of lines are distinguished: 00033 * edges between the skyblue goal and the field, edges between the yellow goal 00034 * and the field, edges between the border and the field, and edges between the 00035 * field lines and the field. 00036 * 00037 * The module scans vertical and horizontal lines in the image from top to bottom 00038 * and from left to right. As the green of the field is very dark, all edges are 00039 * characterized by a big difference of the y-channel of adjacent pixels. An 00040 * increase in the y-channel followed by a decrease is an indication for an edge. 00041 * 00042 * The projection of the pixels on the field plane is used to determine their 00043 * relative position to the robot. 00044 * 00045 * @author <a href="mailto:juengel@informatik.hu-berlin.de">Matthias Juengel</a> 00046 * @author <a href="mailto:roefer@tzi.de">Thomas Röfer</a> 00047 */ 00048 class GT2004ImageProcessor : public ImageProcessor 00049 { 00050 public: 00051 /** 00052 * Constructor. 00053 * @param interfaces The paramters of the GT2004ImageProcessor module. 00054 */ 00055 GT2004ImageProcessor(const ImageProcessorInterfaces& interfaces); 00056 00057 /** Executes the module */ 00058 virtual void execute(); 00059 00060 /** Handles an incoming message 00061 * @param message The message 00062 */ 00063 virtual bool handleMessage(InMessage& message); 00064 00065 private: 00066 double xFactor, /**< Factor to convert the pixel coordinate space to the anglular coordinate space. */ 00067 yFactor; /**< Factor to convert the pixel coordinate space to the anglular coordinate space. */ 00068 int yThreshold; /**< Brightness increase threshold. */ 00069 int vThreshold; /**< Brightness decrease threshold. */ 00070 int orangeCount, /**< Number of columns with ball points. */ 00071 noOrangeCount, /**< Number of columns without a ball point. */ 00072 noRedCount, /**< Number of columns without a red robot point. */ 00073 noBlueCount, /**< Number of columns without a blue robot point. */ 00074 noGoalCount, /**< Number of columns without a opponent goal seen. */ 00075 closestBottom; /**< Closest bottom point on the grid. */ 00076 Vector2<int> firstRed, /**< First red robot point in a cluster. */ 00077 closestRed, /**< Closest red robot point in a cluster. */ 00078 lastRed, /**< Last red robot point in a cluster. */ 00079 firstBlue, /**< First blue robot point in a cluster. */ 00080 closestBlue, /**< Closest blue robot point in a cluster. */ 00081 lastBlue, /**< Last blue robot point in a cluster. */ 00082 firstFlag, /**< First flag point in a cluster. */ 00083 lastFlag; /**< Last flag point in a cluster. */ 00084 bool goalAtBorder; /**< Is the first goal point at the image border? */ 00085 int longestBallRun; 00086 Vector2<int> ballCandidate; 00087 00088 CameraMatrix cmTricot, /**< Camera matrix without tricot height. */ 00089 prevCameraMatrix, /**< The camera matrix of the previous image. */ 00090 prevCmTricot; /**< The tricot matrix of the previous image. */ 00091 00092 ColorCorrector colorCorrector; /**< The color correction tool. */ 00093 00094 GT2004BeaconDetector beaconDetector; /**< The beacon detector */ 00095 00096 GT2004GoalRecognizer goalRecognizer; /**< The goal recognizer. */ 00097 00098 GT2004BallSpecialist ballSpecialist; /**< The ball specialist. */ 00099 00100 GT2004EdgeSpecialist edgeSpecialist; /**< The edge specialist. */ 00101 00102 ImageInfo imageInfo; /**< Additional information about the current image */ 00103 00104 /** 00105 * The function scans columns for line points. 00106 */ 00107 void scanColumns(); 00108 00109 /** 00110 * The function scans rows for line points. 00111 */ 00112 void scanRows(); 00113 00114 /** 00115 * The function scans a line for line points. 00116 * @param start The start point of the line. 00117 * @param end The end point of the line. 00118 * @param vertical Vertical lines are scanned for more information. 00119 * @param noLines Should the line not be scanned for points on field lines or borders? 00120 */ 00121 void scan(const Vector2<int>& start, const Vector2<int>& end, 00122 bool vertical, bool noLines); 00123 00124 /** 00125 * The function clusters points of red and blue robots. 00126 * @param bottomPoint The bottom point of the current scan column. 00127 * @param redFound Has a red robot point been found? In that case, the last 00128 * entry in the lines percept is that point. 00129 * @param blueFound Has a blue robot point been found? In that case, the last 00130 * entry in the lines percept is that point. 00131 */ 00132 void clusterRobots(const unsigned char* bottomPoint, bool redFound, bool blueFound); 00133 00134 /** 00135 * The function clusters flag points. 00136 * @param flagType The type of the flag. 00137 * @param point The center of the pink area. 00138 */ 00139 //void clusterFlags(Flag::FlagType flagType, const Vector2<int>& point); 00140 00141 /** 00142 * The function filters the percepts, i.e. it removes potential misreadings. 00143 */ 00144 void filterPercepts(); 00145 00146 /** 00147 * The function filters the line-percepts, i.e. it removes potential misreadings, for the given line-type. 00148 */ 00149 void filterLinesPercept(LinesPercept& percept, int type, const CameraMatrix& cameraMatrix, const CameraMatrix& prevCameraMatrix, const Image& image); 00150 00151 /** 00152 * The function calculates the angle of an edge at an edge point. 00153 * @param pointInImage The edge point in image coordinates. 00154 * @param pointOnField The edge point in field coordinates. 00155 * @param scanAngle The angle of the scan line the point was found on. 00156 * @param pixelBuffer The pixels on the scan line around the edge point. 00157 * @param againstScanline The flag if bright to dark is detected against the direction of the scanline. 00158 * @param channel The channel the gradient is calculated in. 00159 * @return The angle in relative robot field coordinates. 00160 */ 00161 double calcEdgeAngle( 00162 const Vector2<int>& pointInImage, 00163 const Vector2<int>& pointOnField, 00164 double scanAngle, 00165 const RingBuffer<const unsigned char*,7>& pixelBuffer, 00166 const bool againstScanline = false, 00167 int channel = 0) const; 00168 00169 /** 00170 * The function converts an address to pixel coordinates. 00171 * @param p An address in image.image. 00172 * @return The x- and y-coordinates of the corresponding pixel. 00173 */ 00174 Vector2<int> getCoords(const unsigned char* p) const 00175 { 00176 const int diff(p - &image.image[0][0][0]); 00177 return Vector2<int>(diff % cameraResolutionWidth_ERS7, diff / (cameraResolutionWidth_ERS7 * 6)); 00178 } 00179 00180 //!@name Helpers for grid drawing 00181 //!@{ 00182 const unsigned char* last; 00183 Drawings::Color lineColor; 00184 void plot(const unsigned char* p,Drawings::Color color); 00185 //!@} 00186 00187 double angleBetweenDirectionOfViewAndGround; 00188 00189 int numberOfScannedPixels; 00190 00191 Matrix2x2<double> rotation2x2; 00192 00193 DECLARE_DEBUG_IMAGE(imageProcessorPlayers); 00194 DECLARE_DEBUG_IMAGE(imageProcessorGeneral); 00195 DECLARE_DEBUG_COLOR_CLASS_IMAGE(segmentedImage1); 00196 DECLARE_DEBUG_IMAGE(imageProcessorBall); 00197 DECLARE_DEBUG_IMAGE(imageProcessorGradients); 00198 }; 00199 00200 #endif// __GT2004ImageProcessor_h_ 00201 00202 /* 00203 * $Log: GT2004ImageProcessor.h,v $ 00204 * Revision 1.11 2004/06/29 10:09:12 thomas 00205 * added new algorithm for filtering border- and field-line-percepts 00206 * 00207 * Revision 1.10 2004/06/21 08:15:57 nistico 00208 * The dot product of normalized vectors (versors) is guaranteed to be within [-1, 1] ; 00209 * the angle was not normalized, however. (-pi, pi) 00210 * 00211 * Revision 1.9 2004/06/17 21:13:20 thomas 00212 * modified gradient of line-percepts now have accurate direction 00213 * 00214 * Revision 1.8 2004/06/17 15:52:06 nistico 00215 * Added visualization of camera motion vector on image 00216 * Fixed cameraMatrix.frameNumber=0 problem when playing logfiles 00217 * (the image frame number is copied) 00218 * 00219 * Revision 1.7 2004/06/17 09:24:43 roefer 00220 * Lines percept includes line orientation 00221 * 00222 * Revision 1.6 2004/06/16 18:58:40 roefer 00223 * LinesPercept with angles, does not work yet 00224 * 00225 * Revision 1.5 2004/06/15 10:58:26 thomas 00226 * added edge-specialist, edges-percept, debug-drawings etc. (not yet called from image-processor) 00227 * 00228 * Revision 1.4 2004/06/05 19:48:45 nistico 00229 * Added one more special situation to BeaconDetector 00230 * imageProcessorGradients now visualized edges used by 00231 * BeaconDetector, for debugging 00232 * 00233 * Revision 1.3 2004/06/05 07:58:22 roefer 00234 * Compensation for motion distortions of images 00235 * 00236 * Revision 1.2 2004/05/22 20:44:49 juengel 00237 * Removed manual calibration. 00238 * 00239 * Revision 1.1.1.1 2004/05/22 17:19:46 cvsadm 00240 * created new repository GT2004_WM 00241 * 00242 * Revision 1.3 2004/05/06 16:03:56 nistico 00243 * Supports ColorTable32K through CT32K_LAYOUT switch located into 00244 * GT2004ImageProcessorTools.h 00245 * 00246 * Revision 1.2 2004/05/05 13:27:38 tim 00247 * removed unnecessary lines of code 00248 * 00249 * Revision 1.1 2004/05/04 13:40:19 tim 00250 * added GT2004ImageProcessor 00251 * 00252 */