00001 /** 00002 * @file BoxSpecialist.h 00003 * 00004 * This file contains the definition of class 00005 * 00006 * @author <a href="mailto:sadprofessor@web.de">Bernd Schmidt</a> 00007 */ 00008 #ifndef BOXSPECIALIST_H 00009 #define BOXSPECIALIST_H 00010 00011 00012 #include "RasterSpecialist.h" 00013 #include "Tools/Math/Geometry.h" 00014 #include "Tools/Math/Vector2.h" 00015 #include "RasterStrategy.h" 00016 #include "Tools/Math/Vector3.h" 00017 #include <list> 00018 #include <vector> 00019 #include <algorithm> 00020 #include "Representations/Perception/LandmarksPercept.h" 00021 #include "Modules/ImageProcessor/RasterImageProcessor/REdgeDetection.h" 00022 00023 using namespace std; 00024 00025 /** @class BoxSpecialist 00026 * This class implements the landmark and goal detection algorithms of the RIP.*/ 00027 class BoxSpecialist :public RasterSpecialist 00028 { 00029 00030 public: 00031 /** @class Rectangle 00032 * Struct that represents a rectangle.*/ 00033 struct Rectangle { 00034 /** Upper left point.*/ 00035 Vector2<double> upperLeft; 00036 /** Upper right point.*/ 00037 Vector2<double> upperRight; 00038 /** Bottom left point.*/ 00039 Vector2<double> bottomLeft; 00040 /** Bottom right point.*/ 00041 Vector2<double> bottomRight; 00042 /** Center point of the rectangle.*/ 00043 Vector2<double> center; 00044 }; 00045 /** @class SegmentInfo 00046 * This struct holds information about a segment in the image.*/ 00047 struct SegmentInfo { 00048 /** Constructor */ 00049 SegmentInfo(); 00050 /** Vote for a landmark with yellow.*/ 00051 double lmValidityYellow; 00052 /** Vote for a landmark with blue.*/ 00053 double lmValiditySkyblue; 00054 /** Vote for a goal.*/ 00055 double goalValidity; 00056 /** Durrounding rectangle, aligned to horizon.*/ 00057 Rectangle rect; 00058 /** Number of yellow pixels.*/ 00059 int yellow; 00060 /** Number of skyblue pixels.*/ 00061 int skyblue; 00062 /** Number of pink pixels.*/ 00063 int pink; 00064 /** Number of pixels.*/ 00065 int size; 00066 /** Bottom color of a landmark.*/ 00067 colorClass bottomColor; 00068 /** Top color of a landmark.*/ 00069 colorClass topColor; 00070 /** Pointer to the list of runs.*/ 00071 list<LinePair>* segment; 00072 }; 00073 00074 typedef Geometry::Line Line; 00075 typedef vector<list<RasterSpecialist::LinePair> > SVector; 00076 /** Constructor 00077 * 00078 * @param processor Image processor interfaces. 00079 * @param strategy A strategy is needed for creation (this will change). 00080 */ 00081 BoxSpecialist(RasterImageProcessor &processor,RasterStrategy &strategy); 00082 /** Destructor */ 00083 virtual ~BoxSpecialist(); 00084 /** Invokes the specialist in the second scan stage at position (x,y) 00085 * (this member should be replaced later). 00086 * @param x The x coordinate. 00087 * @param y The y coordinate. 00088 */ 00089 void invokeOnPostScan(int x, int y); 00090 /** Executes the detection algorithm. */ 00091 void executePostProcessing(); 00092 /** Invokes the specialist in the first scan stage at position (x,y) 00093 * (this member should be replaced later). 00094 * @param x The x coordinate. 00095 * @param y The y coordinate.*/ 00096 void invokeOnPreScan(int x,int y); 00097 00098 /** Getter for member type. 00099 * @return The type of the specialist.*/ 00100 virtual int getType(); 00101 /** Initializes the specialist.*/ 00102 virtual void init(); 00103 00104 private: 00105 /** The strategy.*/ 00106 RasterStrategy *strategy; 00107 /** The edge detector.*/ 00108 REdgeDetection edgeScanner; 00109 /** List of LinePairs. The input data of the detection algorithm.*/ 00110 std::list<LinePair> lst_pts; 00111 /** The calculated horizon.*/ 00112 Geometry::Line horizon; 00113 /** The calculated perpendicular to the horizon.*/ 00114 Geometry::Line pHorizon; 00115 /** The threshold for edge-scans of the landmark detection.*/ 00116 int flagThreshold; 00117 /** The threshold for edge-scans of the goal detection.*/ 00118 int goalThreshold; 00119 /** A temporary variable.*/ 00120 Vector2 <int> left_border; 00121 /** The clustered runs.*/ 00122 std::vector<list<LinePair> > segments_img; 00123 /** The calculated informations about the segments.*/ 00124 std::vector<SegmentInfo> infos_img; 00125 /** The bottomPoints of the goal (edges from green to yellow or skyblue).*/ 00126 std::vector<Vector2<int> > bottomPoints; 00127 /** Creates the bounding box aligned to the horizon for each region.*/ 00128 void createBBox(); 00129 /** The goal detection algorithm. 00130 * If a goal was found, a percept will be gemerated. 00131 * @param goal SegmentInfo of a region that might be a goal. 00132 * @return Returns if the related region is detected as a goal. 00133 */ 00134 bool searchGoal(SegmentInfo& goal); 00135 /** The detection algorithm for landmarks. If one is found a percept 00136 * will be generated. 00137 * 00138 * @param flag SegmentInfo of a region that might be a landmark. 00139 * @return Returns if the related region is detected as a landmark. 00140 */ 00141 bool searchLandmark(SegmentInfo& flag); 00142 /** This function detects the accurate shape of a landmark. 00143 * 00144 * @param flag SegmentInfo of a region that was detected as a landmark. 00145 */ 00146 void fitLandmark(SegmentInfo& flag); 00147 /** Detects the free part of the goal and generates a percept. This function 00148 * is not completed yet. 00149 */ 00150 void detectFreePartOfGoal(); 00151 /** Fusions the regions that belong to the same goal. This function is not 00152 * completed yet. But the algorithm is tested. 00153 */ 00154 void fusionGoal(); 00155 /** Merges two regions. The result is stored in seg1. 00156 * @param seg1 The first region. 00157 * @param seg2 The second region. 00158 */ 00159 void mergeBoxes(SegmentInfo& seg1,SegmentInfo& seg2); 00160 /** Counts the colors of segment si. And stores the result in si. 00161 * @param si SegmentInfo of the region. 00162 * @param segment List of runs. 00163 */ 00164 void countColors(SegmentInfo& si, list<LinePair>& segment); 00165 /** A small test for goals. 00166 * @return A validation value.*/ 00167 inline bool missingData(bool ulc, bool urc, bool brc, bool blc, int i); 00168 00169 void calculateAnglesForPoint 00170 ( 00171 /** */ 00172 const Vector2<double>& point, 00173 /** */ 00174 const CameraMatrix& cameraMatrix, 00175 /** */ 00176 const CameraInfo& cameraInfo, 00177 /** */ 00178 Vector2<double>& angles 00179 ); 00180 00181 bool calculatePointOnField 00182 ( 00183 /** */ 00184 const double x, 00185 /** */ 00186 const double y, 00187 /** */ 00188 const CameraMatrix& cameraMatrix, 00189 /** */ 00190 const CameraInfo& cameraInfo, 00191 /** */ 00192 Vector2<int>& pointOnField 00193 ); 00194 /** Creates the validity values for the different kinds of objects. 00195 * The result is stored in info. 00196 * @param info The info represents a region. 00197 */ 00198 void createValidities(SegmentInfo& info); 00199 }; 00200 00201 #endif