00001 /** 00002 * @file RasterImageProcessor.h 00003 * 00004 * This file contains the definition of class RasterImageProcessor. 00005 * 00006 * @author <a href="mailto:sadprofessor@web.de">Bernd Schmidt</a> 00007 */ 00008 #ifndef RASTERIMAGEPROCESSOR_H 00009 #define RASTERIMAGEPROCESSOR_H 00010 00011 #include "Modules/ImageProcessor/ImageProcessorTools/SUSANEdgeDetectionLite.h" 00012 #include "Modules/ImageProcessor/ImageProcessor.h" 00013 #include "Tools/Debugging/DebugDrawings.h" 00014 #include "Tools/Math/Geometry.h" 00015 #include "Tools/Debugging/DebugImages.h" 00016 #include "Modules/ImageProcessor/ImageProcessorTools/ColorCorrector.h" 00017 00018 00019 class RasterSpecialist; 00020 class RasterStrategy; 00021 class RasterImageProcessor; 00022 00023 00024 00025 //#include "./RasterSpecialist.h" 00026 //#include "./RasterStrategy.h" 00027 00028 00029 /**Specialist-types for the RasterImageProcessor.*/ 00030 enum RasterSpecTypes{ 00031 __RBallSpecialist, 00032 __RFieldSpecialist, 00033 __RFlagSpecialist, 00034 __RGoalSpecialist, 00035 __REnemySpecialist, 00036 __REnemyOnlySpecialist, 00037 __RBoxSpecialist, 00038 __REnemySpecialist2, 00039 __RBridgeSpecialist, 00040 maxRasterSpecialists 00041 }; 00042 00043 00044 /** @class RasterImageProcessor 00045 * A class for image-processing. 00046 * @author <a href="mailto:sadprofessor@web.de">Bernd Schmidt</a> 00047 */ 00048 class RasterImageProcessor : public ImageProcessor 00049 { 00050 public: 00051 /** An edge detector */ 00052 SUSANEdgeDetectionLite edgeDetector; 00053 /** The color-corrector*/ 00054 ColorCorrector corrector; 00055 /** The calculated horizon.*/ 00056 Geometry::Line horizon; 00057 00058 /** The consructor. 00059 * @param interfaces The interfaces for the image-processor. 00060 */ 00061 RasterImageProcessor(const ImageProcessorInterfaces& interfaces); 00062 /** Destructor*/ 00063 virtual ~RasterImageProcessor(); 00064 00065 /** Executes the module. */ 00066 virtual void execute(); 00067 /** Handles messages for this module. 00068 * 00069 * @param message Message to handle. 00070 * @return Returns if the message had been handled succesfully. 00071 */ 00072 virtual bool handleMessage(InMessage& message); 00073 /** Getter for a specialist. 00074 * 00075 * @param type Type of the requested specialist. 00076 * @return The specialist of the given type or null if no specialist is registered. 00077 */ 00078 RasterSpecialist *getSpecialist(int type); 00079 /** Sets a specialist, if there is a specialist of the same type registered, it 00080 * will be deleted. 00081 * 00082 * @param spec The specialist to be registered. 00083 */ 00084 void setSpecialist(RasterSpecialist *spec); 00085 /** Removes a specialist from the image-processor. 00086 * Afterwards getSpecialist(type) is NULL. 00087 * 00088 * @param type Type of the specialist. 00089 */ 00090 void removeSpecialist(int type); 00091 00092 /** Getter for the member horizon. 00093 * 00094 * @return the horizon-line for the current image */ 00095 inline Geometry::Line getHorizon(){return horizon;} 00096 /** Adds a point to the LinesPercept. 00097 * @param x x-coordinate 00098 * @param y y-coordinate 00099 * @param type Type for this point of interest. 00100 */ 00101 inline void addFieldPoint(int x,int y,LinesPercept::LineType type){ 00102 Vector2<int> p; 00103 Geometry::calculatePointOnField(x,y,cameraMatrix, 00104 image.cameraInfo,p); 00105 linesPercept.add(type,p); 00106 } 00107 /** Adds a point to the ObstaclesPercept. 00108 * @param nearPointInImage near Point of the seen area 00109 * @param farPointInImage far Point of the seen area 00110 * @param type Type of the free "obstacle"-area 00111 */ 00112 inline void addObstaclePoints( 00113 Vector2<int>& nearPointInImage, 00114 Vector2<int>& farPointInImage, 00115 ObstaclesPercept::ObstacleType type) 00116 { 00117 Vector2<int> nearPoint; 00118 Vector2<int> farPoint; 00119 Geometry::calculatePointOnField( 00120 nearPointInImage.x,nearPointInImage.y,cameraMatrix,image.cameraInfo,nearPoint); 00121 Geometry::calculatePointOnField( 00122 farPointInImage.x,farPointInImage.y,cameraMatrix,image.cameraInfo,farPoint); 00123 00124 bool farOnBorder = 00125 (farPointInImage.x>image.cameraInfo.resolutionWidth-3 00126 || farPointInImage.x < 2 00127 || farPointInImage.y < 2 00128 || farPointInImage.y>image.cameraInfo.resolutionHeight-3); 00129 00130 obstaclesPercept.add(nearPoint,farPoint,farOnBorder,type); 00131 } 00132 /** Tests if the point lies in the valid image area. 00133 * @param p input. 00134 * @return True if the point is valid. 00135 */ 00136 inline bool isValidPoint(Vector2<double>& p){ 00137 if (p.x >= image.cameraInfo.resolutionWidth -2 || p.x <= 1) return false; 00138 if (p.y >= image.cameraInfo.resolutionHeight - 2 || p.y <= 1) return false; 00139 return true; 00140 } 00141 00142 /** Adds a flag to the model. 00143 * 00144 * @param left Center of the left edge. 00145 * @param right Center of the right edge. 00146 * @param top Center of the top edge. 00147 * @param bottom Center of the bottom edge. 00148 * @param type Type of the Flag. 00149 */ 00150 void addFlag(Vector2<double>& left,Vector2<double>& right, 00151 Vector2<double>& top, Vector2<double>& bottom,Flag::FlagType type); 00152 /** Changes the strategy. the old one will be deleted ! 00153 * @param newStrategy The new strategy. 00154 */ 00155 void changeStrategy(RasterStrategy &newStrategy); 00156 00157 /** Minimal x-coordinate of the image-raster.*/ 00158 int minX; 00159 /** Maximal x-coordinate of the image-raster.*/ 00160 int maxX; 00161 /** Minimal y-coordinate of the image-raster.*/ 00162 int minY; 00163 /** Maximal y-coordinate of the image-raster.*/ 00164 int maxY; 00165 /** The margin between two scanlines.*/ 00166 int marginX; 00167 /** The margin between two scanlines.*/ 00168 int marginY; 00169 /** The color-class image.*/ 00170 DECLARE_DEBUG_COLOR_CLASS_IMAGE(segmentedImage1); 00171 00172 private: 00173 /** Initializes the module.*/ 00174 void init(); 00175 /** The concurrent specialists.*/ 00176 RasterSpecialist *specials[maxRasterSpecialists]; 00177 /** The active strategy.*/ 00178 RasterStrategy *strategy; 00179 /** The new strategy in the next frame.*/ 00180 RasterStrategy *waitingStrategy; 00181 00182 DECLARE_DEBUG_IMAGE(imageProcessorGeneral); 00183 00184 /*DECLARE_DEBUG_IMAGE(imageProcessorScanLines); 00185 DECLARE_DEBUG_IMAGE(imageProcessorGradients);*/ 00186 00187 00188 DECLARE_DEBUG_IMAGE(imageProcessorBall); 00189 DECLARE_DEBUG_IMAGE(imageProcessorObstacles); 00190 DECLARE_DEBUG_IMAGE(imageProcessorFlagsAndGoals); 00191 DECLARE_DEBUG_IMAGE(imageProcessorGround); 00192 00193 //DECLARE_DEBUG_COLOR_CLASS_IMAGE(segmentedImage3); 00194 //DECLARE_DEBUG_COLOR_CLASS_IMAGE(segmentedImage2); 00195 //DECLARE_DEBUG_IMAGE(classificationY); 00196 //DECLARE_DEBUG_IMAGE(classificationU); 00197 //DECLARE_DEBUG_IMAGE(classificationV); 00198 //DECLARE_DEBUG_IMAGE(colorFrequency); 00199 00200 }; 00201 00202 00203 #endif 00204 00205 00206 /* 00207 * Change log : 00208 * 00209 * $Log: RasterImageProcessor.h,v $ 00210 * Revision 1.5 2004/09/06 12:02:26 schmidtb 00211 * commented almost all members, removed warnings in documentation 00212 00213 * did further code clean up 00214 * 00215 * Revision 1.4 2004/09/03 11:32:13 nistico 00216 * References to MSH2004ColorCorrector removed, now uses the unified ColorCorrector 00217 * 00218 * Revision 1.3 2004/09/02 07:59:29 schmidtb 00219 * Added RasterImageProcessor to repository, because we used it for the OpenChallenge. 00220 * 00221 * Revision 1.17 2004/05/25 13:27:33 schmidtb 00222 * modified version of rip for open-challenge 00223 * 00224 * Revision 1.16 2004/04/08 17:14:26 wachter 00225 * GT04 checkin of Microsoft-Hellounds 00226 * 00227 * Revision 1.16 2004/03/25 15:21:19 pg_besc 00228 * made some changes 00229 * 00230 * Revision 1.15 2004/03/17 18:27:45 koh 00231 * warnings and errors removed 00232 * 00233 * Revision 1.14 2004/03/11 20:32:36 schmidtb 00234 * new version of rip 00235 * 00236 * Revision 1.13 2004/03/08 01:39:02 roefer 00237 * Interfaces should be const 00238 * 00239 * Revision 1.12 2004/03/03 12:53:21 schmidtb 00240 * color correction integrated 00241 * 00242 * Revision 1.11 2004/03/01 14:17:26 koh 00243 * added new strategy "RFlexibleStrategy" + new specialist "EnemyOnlySpecialist"; 00244 * changed references to "RDefaultStrategy" to references to "RasterStrategy" in RFieldSpecialist 00245 * added Geometry::Line horizon to "RasterStrategy" 00246 * 00247 * Revision 1.10 2004/02/28 17:16:47 schmidtb 00248 * debugged and made some changes 00249 * 00250 * Revision 1.9 2004/02/04 13:12:23 nistico 00251 * Removed unneeded references in RasterImageProcessor to ManualCalibration, which were binding it 00252 * to ColorTable64 00253 * 00254 * Revision 1.8 2004/02/02 13:42:12 schmidtb 00255 * merged sources of RIP. added som functions. 00256 * 00257 * Revision 1.7 2004/01/23 15:44:01 deom 00258 * New specialist :: BoxSpecialist 00259 * Recognizes both landmarks and goals 00260 * 00261 * Revision 1.6 2003/12/15 13:55:32 schmidtb 00262 * Merged and patched new version of RasterImageProcessor. 00263 * 00264 * Revision 1.5 2003/12/08 15:02:55 schmidtb 00265 * new version of RIP 00266 * 00267 * Revision 1.4 2003/12/04 09:51:23 schmidtb 00268 * better BallSpecialist 00269 * 00270 * Revision 1.3 2003/11/20 10:26:56 schmidtb 00271 * Ball Detection added 00272 * 00273 * Revision 1.2 2003/11/13 10:41:29 schmidtb 00274 * renewed RBallSpeciaslist and Strategy 00275 * 00276 * Revision 1.1 2003/11/12 13:13:20 schmidtb 00277 * new RasterImageProcessor added 00278 * 00279 * 00280 */