00001 /** 00002 * @file CheckerboardDetector.h 00003 * 00004 * Definition of class Checkerboard 00005 * 00006 * @author Uwe Düffert 00007 */ 00008 00009 00010 #ifndef __CheckerboardDetector_h_ 00011 #define __CheckerboardDetector_h_ 00012 00013 #include "ImageProcessor.h" 00014 #include "Tools/Debugging/DebugImages.h" 00015 #include "Tools/Math/Geometry.h" 00016 #include "Tools/Math/Vector2.h" 00017 00018 /** 00019 * @class CheckerboardDetector 00020 * 00021 * A solution of the ImageProcessor module that looks for vertical checkerboards 00022 * (a row of black and white ~10x10cm tiles with a white boarder and a middle mark 00023 * in eye height that allows precise location of the robot relative to the 00024 * checkerboard from a single image 00025 * 00026 * @author <A href=mailto:dueffert@informatik.hu-berlin.de>Uwe Düffert</A> 00027 */ 00028 class CheckerboardDetector : public ImageProcessor 00029 { 00030 public: 00031 /** 00032 * Constructor. 00033 * @param interfaces The paramters of the ImageProcessor module. 00034 */ 00035 CheckerboardDetector(const ImageProcessorInterfaces& interfaces); 00036 00037 /** Executes the module */ 00038 virtual void execute(); 00039 00040 private: 00041 DECLARE_DEBUG_IMAGE(imageProcessorGeneral); 00042 00043 int minY,maxY,maxDelta; 00044 typedef Vector2<double> v2dArray[100]; 00045 typedef bool bArray[100]; 00046 00047 /** calculates the exact middle of an black white transition in a PixeledLine. 00048 * @param p1 one point in camera coordinates 00049 * @param p2 another point in camera coordinates 00050 * @return the resulting arc difference between these 2 points 00051 */ 00052 double getAngleBetweenScreenPoints(const Vector2<double>& p1, const Vector2<double>& p2); 00053 00054 /** calculates the exact middle of an black white transition in a PixeledLine. 00055 * @param lin the PixeledLine to investigate 00056 * @param start index of black white transition in lin to investigate 00057 * @param amount the total change of brightness in this black white transition 00058 * @return the resulting position of the middle of the black white transition 00059 */ 00060 Vector2<double> getExactTransitionMiddle(const Geometry::PixeledLine lin, const int start, const int amount); 00061 00062 /** finds all black white transitions in a PixeledLine 00063 * @param lin the PixeledLine to investigate 00064 * @param transPos returned array of found transition middle positions 00065 * @param transWhiteBlack returned array of booleans whether transition is from white to black or vice versa 00066 * @param numOfTrans returned number of found transitions 00067 */ 00068 void getTransitionsOnLine(const Geometry::PixeledLine lin, v2dArray* transPos, bArray* transWhiteBlack, int& numOfTrans); 00069 00070 /** finds the first transition to white starting from within a black block 00071 * @param lin the PixeledLine to investigate 00072 * @return the position of the found transition to white, (-1,-1) otherwise 00073 */ 00074 Vector2<double> getTransitionToWhite(const Geometry::PixeledLine lin); 00075 00076 /** calculate a middle perpendicular to t1-t2, find transitions to white on that perpendicular and return the middle between the transitions to white. This gives a better and more secure black block middle than the the middle between t1 and t2 itself. 00077 * @param t1 beginning of black block 00078 * @param t2 end of black block 00079 * @param len returned length of the found perpendicular in black, 0 otherwise 00080 * @return the position of of found middle of the perpendicular (if it exists), (-1,-1) otherwise 00081 */ 00082 Vector2<double> getMiddleAndLengthOfPerpendicular(const Vector2<double> t1, const Vector2<double> t2, double& len); 00083 00084 /** approximates a line f(x)=m*x+n through a number of points 00085 * @param points an array of points that should be approximated by a line 00086 * @param numOfPoints number of points in the array 00087 * @param m the returned Anstieg of the line (f(x)=mx+n) 00088 * @param n the returned offset of the line (f(x)=mx+n) 00089 * @return true if a line (candidate) was found 00090 */ 00091 bool getLineThroughPixelsCandidate(const v2dArray* points, const int numOfPoints, double& m, double& n); 00092 00093 /** approximates a PixeledLine through a number of points without found elopers 00094 * @param points an array of points that should be approximated by a line 00095 * @param numOfPoints number of points in the array 00096 * @param lin the returned PixeledLine 00097 * @return true if a line was found 00098 */ 00099 bool getLineThroughPixels(const v2dArray* points, const int numOfPoints, Geometry::PixeledLine& lin); 00100 00101 /** calculate a position relative to the checkerboard 00102 * @param alpha2 absolute angle between the left most and the middle seen black white transition 00103 * @param a2 absolute distance on the checkboard between the left most and the middle seen black white transition 00104 * @param alpha1 absolute angle between the middle and the right most seen black white transition 00105 * @param a1 absolute distance on the checkboard between the middle and the right most seen black white transition 00106 * @return returned position relative to seen middle transition in checkerboard 00107 */ 00108 Vector2<double> getPositionFromAngles(const double alpha2,const double a2,const double alpha1,const double a1); 00109 00110 /** calculate the real y position of a black white transition on the checkerboard 00111 * @param index index of the black white transition relative to the left side (0) of the large black middle block, left is negative, right positive 00112 * @return real y position 00113 */ 00114 double yPosFromTransitionIndex(int index); 00115 }; 00116 00117 00118 #endif// __CheckerboardDetector_h_ 00119 00120 /* 00121 * $Log: CheckerboardDetector.h,v $ 00122 * Revision 1.1.1.1 2004/05/22 17:19:26 cvsadm 00123 * created new repository GT2004_WM 00124 * 00125 * Revision 1.4 2004/03/08 01:38:56 roefer 00126 * Interfaces should be const 00127 * 00128 * Revision 1.3 2004/02/29 13:46:48 dueffert 00129 * localization in critical cases improved 00130 * 00131 * Revision 1.2 2003/12/15 10:57:24 dueffert 00132 * calculation bug fixed 00133 * 00134 * Revision 1.1 2003/10/06 14:10:13 cvsadm 00135 * Created GT2004 (M.J.) 00136 * 00137 * Revision 1.3 2003/09/01 10:20:11 juengel 00138 * DebugDrawings clean-up 2 00139 * DebugImages clean-up 00140 * MessageIDs clean-up 00141 * Stopwatch clean-up 00142 * 00143 * Revision 1.2 2003/08/08 11:24:51 dueffert 00144 * doxygen docu corrected 00145 * 00146 * Revision 1.1 2003/07/30 14:50:02 dueffert 00147 * CheckerboardDetector added 00148 * 00149 * Revision 1.5 2003/02/21 14:16:12 dueffert 00150 * recognition of our checkerboard continued, see logs/special_localisator2.log 00151 * 00152 * Revision 1.4 2003/02/20 15:43:27 dueffert 00153 * bug fixed 00154 * 00155 * Revision 1.3 2003/02/20 15:32:17 dueffert 00156 * work continued 00157 * 00158 * Revision 1.2 2003/02/19 15:57:34 dueffert 00159 * some checkerboard detection work 00160 * 00161 * Revision 1.1 2003/01/22 15:00:03 dueffert 00162 * checkerboard stuff added 00163 * 00164 * 00165 */