00001 /** 00002 * @file RBallSpecialist2.h 00003 * 00004 * This file contains the definition of class RBallSpecialist2. 00005 * 00006 * @author <a href="mailto:sadprofessor@web.de">Bernd Schmidt</a> 00007 */ 00008 #ifndef RBALLSPECIALIST2_H 00009 #define RBALLSPECIALIST2_H 00010 00011 00012 00013 00014 #include "RasterSpecialist.h" 00015 #include "Tools/Math/Geometry.h" 00016 #include <vector> 00017 #include <list> 00018 #include "Tools/Math/Vector2.h" 00019 #include "RasterStrategy.h" 00020 #include "Modules/ImageProcessor/RasterImageProcessor/REdgeDetection.h" 00021 00022 00023 /** 00024 * @class RBallSpecialist2 00025 * Implements a detection algorithm for balls. 00026 * 00027 */ 00028 00029 class RBallSpecialist2 :public RasterSpecialist 00030 { 00031 /** */ 00032 enum{MAX_EDGE_POINTS = 30,MAX_CIRCLE_DIST = 2,EDGE_THR = 30,SCAN_THR = 30}; 00033 public: 00034 00035 /** Constructor 00036 * 00037 * @param processor The image processor interfaces. 00038 * @param strategy The strategy. 00039 */ 00040 RBallSpecialist2(RasterImageProcessor &processor,RasterStrategy &strategy); 00041 /** Destructor*/ 00042 virtual ~RBallSpecialist2(); 00043 /** Invokes the specialist in the second scan stage at position (x,y) 00044 * (this member should be replaced later). 00045 * @param x The x coordinate. 00046 * @param y The y coordinate. 00047 */ 00048 void invokeOnPostScan(int x, int y); 00049 /** Executes the detection algorithm. */ 00050 void executePostProcessing(); 00051 /** Invokes the specialist in the first scan stage at position (x,y) 00052 * (this member should be replaced later). 00053 * @param x The x coordinate. 00054 * @param y The y coordinate.*/ 00055 void invokeOnPreScan(int x,int y); 00056 /** Getter for the type. 00057 * @return The type of the specialist. 00058 */ 00059 virtual int getType(); 00060 /** Initializes the specialist.*/ 00061 virtual void init(); 00062 /** Validates the circle, by comparing it to a color pattern. 00063 * 00064 * @param circle The circle. 00065 * @return The validity. 00066 */ 00067 double validateCircle(Geometry::Circle &circle); 00068 /** Validates the circle, by calculating the percantage of 00069 * edge points near the circle. 00070 * 00071 * @param circle The circle. 00072 * @return The validity of the circle. 00073 */ 00074 double validateEdgePoints(Geometry::Circle &circle); 00075 /** Calculates the coordinates of a vector that looks in direction angle. 00076 * Only a helper. 00077 * 00078 * @param angle input 00079 * @param x output variable 00080 * @param y output variable 00081 */ 00082 inline void getCoordinatesByAngle(double angle,double& x,double& y){ 00083 x = cos(angle); 00084 y = sin(angle); 00085 } 00086 00087 /** A temporary variable.*/ 00088 Vector2<int> temp; 00089 /** The runs to analyze.*/ 00090 std::list<LinePair> rows; 00091 00092 private: 00093 /** The strategy.*/ 00094 RasterStrategy *strategy; 00095 00096 //SUSANEdgeDetectionLite edgeDetector; 00097 00098 /** The edge detector.*/ 00099 REdgeDetection edgeScanner; 00100 /** The normal threshold.*/ 00101 int threshold; 00102 /** The threshold for large balls.*/ 00103 int minEdgeThreshold; 00104 00105 /** Adds the Ball to the BallPercept. 00106 * Makes some small tests befor generating a percept. 00107 * 00108 * @param circle The circle detected as a ball. 00109 * @param validity The color validity for this circle. 00110 */ 00111 void addBallPercept(Geometry::Circle &circle,double validity); 00112 /** Approximates a circle for small regions. 00113 * 00114 * @param circle The circle. 00115 * @return Validity of the circle. 00116 */ 00117 double calculateSmallCircle(Geometry::Circle& circle); 00118 /** Approximates the circle with a randomized algorithm. 00119 * @param circle The result. 00120 * @return The validity of the result. 00121 */ 00122 double calculateCircleByEdges(Geometry::Circle& circle); 00123 /** Approximates the circle with a randomized algorithm. 00124 * Edge points are filtered with a star scan, which has its 00125 * origin in the center of the box. 00126 * 00127 * @param input The bounding box of the region seems to belong to a ball. 00128 * @param circle The result. 00129 * @return The validity of the result. 00130 */ 00131 double calculateLargeCircle(const Box& input,Geometry::Circle& circle); 00132 /** Filters the edge points with a contrast filter. 00133 * 00134 * @param segment The region, which is the input data. 00135 * @return True, if selected more than 3 points. 00136 */ 00137 bool filterBallPoints(std::list<LinePair>& segment); 00138 /** Builds a bounding box for a segment. 00139 * 00140 * @param segment The input data. 00141 * @param box The result. 00142 * @return True, if building was succesful. 00143 */ 00144 bool createBox(std::list<LinePair>& segment,Box& box); 00145 /** Calculates the average distance of the edge points to the circle. 00146 * 00147 * @param circle The circle. 00148 * @return The average distance of all edge points. 00149 */ 00150 double middleEdgePointDist(Geometry::Circle &circle); 00151 00152 /** A buffer for the edge points of a region.*/ 00153 std::vector<Vector2<int> > points; 00154 /** The number of edge points.*/ 00155 int numberOfEdgePoints; 00156 /** The roundness of the last detected circle.*/ 00157 double roundness; 00158 00159 /** The function defines a filter used in filterBallPoints(). 00160 * 00161 * @param x The x-coordinate. 00162 * @param y The y-coordinate. 00163 * @return True if the point lies on a edge. 00164 */ 00165 inline bool isEdge(int x,int y){ 00166 // return edgeDetector.isEdgePoint(rip->image,x,y, 00167 // SUSANEdgeDetectionLite::componentA); 00168 return edgeScanner.isHorizontalEdge(x,y) || edgeScanner.isVerticalEdge(x,y); 00169 } 00170 /** Setter for the edge filter threshold. 00171 * 00172 * @param threshold A threshold. 00173 */ 00174 void setThreshold(int threshold); 00175 }; 00176 00177 #endif 00178 00179 /* 00180 * Change log : 00181 * 00182 * $Log: RBallSpecialist2.h,v $ 00183 * Revision 1.6 2004/09/09 11:08:04 spranger 00184 * renamed GT2004EdgeDetection to REdgeDetection for consistency 00185 * 00186 * Revision 1.5 2004/09/08 14:39:02 wachter 00187 * - Fixed some doxygen-errors 00188 * 00189 * Revision 1.4 2004/09/06 12:02:26 schmidtb 00190 * commented almost all members, removed warnings in documentation 00191 00192 * did further code clean up 00193 * 00194 * Revision 1.3 2004/09/02 07:59:29 schmidtb 00195 * Added RasterImageProcessor to repository, because we used it for the OpenChallenge. 00196 * 00197 * Revision 1.3 2004/05/25 13:27:34 schmidtb 00198 * modified version of rip for open-challenge 00199 * 00200 * Revision 1.5 2004/04/22 16:57:26 pg_besc 00201 * new version of RBallSpecialist2, now omidirectional scans for detection 00202 * 00203 * Revision 1.4 2004/04/20 08:12:38 pg_besc 00204 * fixed bug 00205 * 00206 * Revision 1.3 2004/04/20 07:50:27 pg_besc 00207 * new version of pre scan 00208 * 00209 * Revision 1.2 2004/03/25 15:26:10 pg_besc 00210 * made some changes 00211 * 00212 */