00001 /** 00002 * @file VLCImageProcessor.h 00003 * 00004 * Definition of class VLCImageProcessor 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 * @author <a href="mailto:stefan.czarnetzki@uni-dortmund.de">Stefan Czarnetzki</a> 00009 */ 00010 00011 #ifndef __VLCImageProcessor_h_ 00012 #define __VLCImageProcessor_h_ 00013 00014 #include "Modules/ImageProcessor/ImageProcessor.h" 00015 #include "Tools/Debugging/DebugDrawings.h" 00016 #include "Tools/Math/Geometry.h" 00017 #include "Tools/Debugging/DebugImages.h" 00018 #include "Tools/RingBuffer.h" 00019 #include "Modules/ImageProcessor/ImageProcessorTools/ColorCorrector.h" 00020 #include "VLCImageProcessorTools.h" 00021 #include "VLCGoalRecognizer.h" 00022 #include "VLCBallSpecialist.h" 00023 #include "VLCBeaconDetector.h" 00024 // #include "VLCEdgeSpecialist.h" 00025 #include "Tools/Actorics/RobotDimensions.h" 00026 #include "Tools/RobotConfiguration.h" 00027 #include "Tools/Math/Common.h" 00028 #include "VLCClustering.h" 00029 #include "VLCLineFinder_DeterministicApproach.h" 00030 #include "VLCCenterCircleFinder.h" 00031 00032 /** 00033 * @class VLCImageProcessor 00034 * 00035 * The lines image processor recognizes characteristic lines in the image. 00036 * Four types of lines are distinguished: 00037 * edges between the skyblue goal and the field, edges between the yellow goal 00038 * and the field, edges between the border and the field, and edges between the 00039 * field lines and the field. 00040 * 00041 * The module scans vertical and horizontal lines in the image from top to bottom 00042 * and from left to right. As the green of the field is very dark, all edges are 00043 * characterized by a big difference of the y-channel of adjacent pixels. An 00044 * increase in the y-channel followed by a decrease is an indication for an edge. 00045 * 00046 * The projection of the pixels on the field plane is used to determine their 00047 * relative position to the robot. 00048 * 00049 * @author <a href="mailto:juengel@informatik.hu-berlin.de">Matthias Juengel</a> 00050 * @author <a href="mailto:roefer@tzi.de">Thomas Röfer</a> 00051 */ 00052 class VLCImageProcessor : public ImageProcessor 00053 { 00054 public: 00055 /** 00056 * Constructor. 00057 * @param interfaces Collection of references to other objects, e.g. the current image, 00058 * required by this module. 00059 */ 00060 VLCImageProcessor(const ImageProcessorInterfaces& interfaces); 00061 00062 /** 00063 * Destructor. 00064 */ 00065 ~VLCImageProcessor() 00066 { 00067 delete colorTableVeryDark; 00068 delete colorTableDark; 00069 delete colorTableMedium; 00070 delete colorTableBright; 00071 } 00072 00073 /** 00074 * Main method. Called on every captured image. 00075 */ 00076 virtual void execute(); 00077 00078 /** 00079 * Handles an incoming message 00080 * @param message The message 00081 */ 00082 virtual bool handleMessage(InMessage& message); 00083 00084 /** 00085 * Parameters for the scanning grid. 00086 * Only one in four scanlines run from the horizon to the bottom of the image. In between 00087 * of those, there are one medium and two short lines, so that the grid is more dense near 00088 * the horizon. 00089 * The parameter verticalScanlineSpacing specifies the distance between the vertical scan 00090 * lines. 00091 */ 00092 static const double verticalScanLineTopAboveHorizon; 00093 static const double verticalScanLineLength13; 00094 static const double verticalScanLineLength2; 00095 static const double verticalScanLineSpacing; 00096 00097 00098 private: // methods 00099 00100 /** 00101 * Calculates the vertical lines and calls scan(...) on each of them. The vertical lines 00102 * are more dense near the horizon, since objects are further away and hence smaller. 00103 */ 00104 void scanColumns(); 00105 00106 /** 00107 * Calculates the horizontal lines and calls scan 00108 */ 00109 void scanRows(); 00110 00111 /** 00112 * The function scans a line for varous things (??). 00113 * @param start The start point of the line. 00114 * @param end The end point of the line. 00115 * @param vertical The scanline is a vertical line (for specialist that differentiate 00116 * between vertical and horizontal scanlines). 00117 * @param noLines If true, don't look for field lines. 00118 * @param pixelsRelevantForGoals Number of pixels on the scanline (from the top) that 00119 * are relevant for the GoalRecognizer. 00120 */ 00121 void scan(const Vector2<int>& start, const Vector2<int>& end, 00122 bool vertical, bool noLines, int pixelsRelevantForGoal); 00123 00124 00125 private: 00126 static const double minAngleBetweenFlagAndGoal; 00127 double xFactor, /**< Factor to convert the pixel coordinate space to the anglular coordinate space. */ 00128 yFactor; /**< Factor to convert the pixel coordinate space to the anglular coordinate space. */ 00129 int yThreshold; /**< Brightness increase threshold. */ 00130 int vThreshold; /**< Brightness decrease threshold. */ 00131 int orangeCount, /**< Number of columns with ball points. */ 00132 noOrangeCount, /**< Number of columns without a ball point. */ 00133 noRedCount, /**< Number of columns without a red robot point. */ 00134 noBlueCount, /**< Number of columns without a blue robot point. */ 00135 noGoalCount, /**< Number of columns without a opponent goal seen. */ 00136 closestBottom; /**< Closest bottom point on the grid. */ 00137 Vector2<int> firstRed, /**< First red robot point in a cluster. */ 00138 closestRed, /**< Closest red robot point in a cluster. */ 00139 lastRed, /**< Last red robot point in a cluster. */ 00140 firstBlue, /**< First blue robot point in a cluster. */ 00141 closestBlue, /**< Closest blue robot point in a cluster. */ 00142 lastBlue, /**< Last blue robot point in a cluster. */ 00143 firstFlag, /**< First flag point in a cluster. */ 00144 lastFlag; /**< Last flag point in a cluster. */ 00145 bool goalAtBorder; /**< Is the first goal point at the image border? */ 00146 00147 00148 /** Useful information about the current image that is calculated by the ImageProcessor 00149 object and may be used by the specialist (avoiding recalculation) like the horizon, 00150 etc. */ 00151 ImageInfo imageInfo; 00152 00153 00154 int longestBallRun; 00155 Vector2<int> ballCandidate; 00156 VLCClustering ballClustering; 00157 VLCLineFinder_DeterministicApproach lineFinder; 00158 VLCCenterCircleFinder circleFinder; 00159 00160 CameraMatrix cmTricot, /**< Camera matrix without tricot height. */ 00161 prevCmTricot; /**< The tricot matrix of the previous image. */ 00162 // prevCameraMatrix moved to ImageInfo! 00163 00164 ColorCorrector colorCorrector; /**< The color correction tool. */ 00165 00166 /** Goal specialists to recognize the goals (one for each color). */ 00167 VLCGoalRecognizer goalSpecialistY, goalSpecialistB; 00168 00169 /** Other specialists. */ 00170 VLCBeaconDetector beaconDetector; /**< The beacon detector */ 00171 VLCBallSpecialist ballSpecialist; /**< The ball specialist. */ 00172 // VLCEdgeSpecialist edgeSpecialist; /**< The edge specialist. */ 00173 00174 00175 /** 00176 * The function clusters points of red and blue robots. 00177 * @param bottomPoint The bottom point of the current scan column. 00178 * @param redFound Has a red robot point been found? In that case, the last 00179 * entry in the lines percept is that point. 00180 * @param blueFound Has a blue robot point been found? In that case, the last 00181 * entry in the lines percept is that point. 00182 */ 00183 void clusterRobots(const unsigned char* bottomPoint, bool redFound, bool blueFound); 00184 00185 /** 00186 * The function clusters flag points. 00187 * @param flagType The type of the flag. 00188 * @param point The center of the pink area. 00189 */ 00190 //void clusterFlags(Flag::FlagType flagType, const Vector2<int>& point); 00191 00192 /** 00193 * The function filters the percepts, i.e. it removes potential misreadings. 00194 */ 00195 void filterPercepts(); 00196 00197 /** 00198 * The function filters the line-percepts, i.e. it removes potential misreadings, for the given line-type. 00199 */ 00200 void filterLinesPercept(LinesPercept& percept, int type, const Image& image); 00201 00202 /** 00203 * The function calculates the angle of an edge at an edge point. 00204 * @param angleInImage The angle in image coordinates to be determined. 00205 * @param angleOnField The angle in relative robot field coordinates to be determined. 00206 * @param pointInImage The edge point in image coordinates. 00207 * @param pointOnField The edge point in field coordinates. 00208 * @param scanAngle The angle of the scan line the point was found on. 00209 * @param pixelBuffer The pixels on the scan line around the edge point. 00210 * @param againstScanline The flag if bright to dark is detected against the direction of the scanline. 00211 * @param borderOrLine The flag if this edge belongs to a border or a line (white to green edge). 00212 * @param channel The channel the gradient is calculated in. 00213 * @return Whether the angle in field coordinates could be determined 00214 */ 00215 bool calcEdgeAngle( 00216 double& angleInImage, 00217 double& angleOnField, 00218 const Vector2<int>& pointInImage, 00219 const Vector2<int>& pointOnField, 00220 double scanAngle, 00221 const RingBuffer<const unsigned char*,7>& pixelBuffer, 00222 const bool againstScanline = false, 00223 const bool borderOrLine = true, 00224 int channel = 0); 00225 00226 /** 00227 * The function converts an address to pixel coordinates. 00228 * @param p An address in image.image. 00229 * @return The x- and y-coordinates of the corresponding pixel. 00230 */ 00231 Vector2<int> getCoords(const unsigned char* p) const 00232 { 00233 const int diff(p - &image.image[0][0][0]); 00234 return Vector2<int>(diff % cameraResolutionWidth_ERS7, diff / (cameraResolutionWidth_ERS7 * 6)); 00235 } 00236 00237 //!@name Helpers for grid drawing 00238 //!@{ 00239 const unsigned char* last; 00240 Drawings::Color lineColor; 00241 void plot(const unsigned char* p,Drawings::Color color); 00242 //!@} 00243 00244 double angleBetweenDirectionOfViewAndGround; 00245 00246 int numberOfScannedPixels; 00247 00248 // for VLC 00249 double averageY,averageU,averageV; 00250 RingBuffer<double,5> averageYBuffer; 00251 ColorTable64 * colorTableVeryDark; 00252 ColorTable64 * colorTableDark; 00253 ColorTable64 * colorTableMedium; 00254 ColorTable64 * colorTableBright; 00255 ColorTable * bestColorTable; 00256 double vd2d,d2m,m2b; // thresholds 00257 // 00258 00259 Matrix2x2<double> rotation2x2; 00260 00261 DECLARE_DEBUG_IMAGE(imageProcessorPlayers); 00262 DECLARE_DEBUG_IMAGE(imageProcessorGeneral); 00263 DECLARE_DEBUG_COLOR_CLASS_IMAGE(segmentedImage1); 00264 DECLARE_DEBUG_IMAGE(imageProcessorBall); 00265 DECLARE_DEBUG_IMAGE(imageProcessorGradients); 00266 00267 N_DECLARE_DEBUG_IMAGE(colorCorrected); 00268 N_DECLARE_DEBUG_IMAGE(colorCorrected2); 00269 N_DECLARE_DEBUG_COLOR_CLASS_IMAGE(segmented); 00270 N_DECLARE_DEBUG_IMAGE(ball); 00271 N_DECLARE_DEBUG_IMAGE(edgeDetection); 00272 N_DECLARE_DEBUG_GRAY_SCALE_IMAGE(scanLines); 00273 }; 00274 00275 #endif// __VLCImageProcessor_h_
1.3.6