Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Modules/ImageProcessor/GT2004ImageProcessor/GT2004BallSpecialist.h

Go to the documentation of this file.
00001 /**
00002 * @file GT2004BallSpecialist.h
00003 * 
00004 * This file contains a class for Image Processing.
00005 * @author <A href=mailto:juengel@informatik.hu-berlin.de> Matthias Juengel</A>
00006 * @author Max Risler
00007 * @author <A href=mailto:brunn@sim.tu-darmstadt.de> Ronnie Brunn</A>
00008 * @author <A href=mailto:mkunz@sim.tu-darmstadt.de> Michael Kunz</A>
00009 * @author <a href="mailto:walter.nistico@uni-dortmund.de">W alter Nistico</a>
00010 */
00011 
00012 #ifndef __GT2004BallSpecialist_h_
00013 #define __GT2004BallSpecialist_h_
00014 
00015 #include "Tools/Math/Geometry.h"
00016 #include "Tools/Debugging/DebugImages.h"
00017 #include "Representations/Perception/ColorTable.h"
00018 #include "Representations/Perception/Image.h"
00019 #include "Representations/Perception/CameraMatrix.h"
00020 #include "Representations/Perception/BallPercept.h"
00021 #include "Modules/ImageProcessor/ImageProcessorTools/ColorCorrector.h"
00022 #include "Modules/ImageProcessor/ImageProcessorTools/BresenhamLineScan.h"
00023 #include "Tools/Math/Common.h"
00024 
00025 /**
00026 The BallSpecialist finds a single ball in an image.
00027 */
00028 class GT2004BallSpecialist  
00029 {
00030 public:
00031   GT2004BallSpecialist(const ColorCorrector& colorCorrector);
00032   
00033   /** 
00034   * Searches for the ball in the image, starting from the secified point. 
00035   */
00036   void searchBall
00037   (
00038     const Image& image,
00039     const ColorTable& colorTable,
00040     const CameraMatrix& cameraMatrix,
00041     const CameraMatrix& prevCameraMatrix,
00042     int x, int y,
00043     BallPercept& ballPercept
00044   );
00045   
00046   /**
00047   * Returns the Similarity of the given color to orange.
00048   */
00049   unsigned char getSimilarityToOrange (unsigned char y, unsigned char u, unsigned char v)
00050   {
00051 /*      double r = y + 1.140 * (u - 128);
00052       double g = y - 0.394 * (v - 128) - 0.581 * (u - 128);
00053       double b = y + 2.028 * (v - 128);
00054       if(r < 0) r = 0; if(r > 255) r = 255;
00055       if(g < 0) g = 0; if(g > 255) g = 255;
00056       if(b < 0) b = 0; if(b > 255) b = 255;*/
00057     unsigned char r, g, b;
00058     Image::convertFromYCbCrToRGB(y, u, v, r, g, b);
00059 
00060 //    return (unsigned char) min(max(r-2*b-abs(2*g-r),0),255);
00061     return (unsigned char) min(max(r - 2*b - 3*max((g-r/2),0) - (3*max((r/2-g),0))/2 ,0),255);
00062   }
00063 
00064 private:
00065   /**
00066   * The class represents a ball point.
00067   */
00068   class BallPoint : public Vector2<int>
00069   {
00070   public:
00071     BallPoint() : atBorder(false), greenIsClose(true), yellowIsClose(false), hardEdge(true){};
00072     bool greenIsClose;
00073     bool yellowIsClose;
00074     bool hardEdge;
00075     bool atBorder;
00076 
00077     BallPoint& operator=(const Vector2<int>& other)
00078     {
00079       x = other.x;
00080       y = other.y;
00081 
00082       return *this;
00083     }
00084   };
00085 
00086   class BallPointList
00087   {
00088   public:
00089     BallPointList() : number(0) {};
00090 
00091     enum {maxNumberOfPoints = 400}; /**< The maximum number of ball points. */
00092     BallPoint ballPoints[maxNumberOfPoints]; /**< The ball points. */
00093     int number; /**< The actual number of ball points. */
00094 
00095     void add(const BallPoint& ballPoint);
00096 
00097     BallPoint& operator[] (int i) { return ballPoints[i]; }
00098     const BallPoint& operator[] (int i) const { return ballPoints[i]; }
00099   };
00100 
00101   /** Scan for the ball starting at a given trigger point */
00102   void scanForBallPoints
00103   (
00104    const Image& image,
00105    const CameraInfo& bwCameraInfo,
00106    const ColorTable& colorTable,
00107    int x, int y,
00108    BallPointList& ballPoints,
00109    int& countAmbiguous,
00110    int& countOrange,
00111    int& maxOrangePerLine,
00112    int& countPixel
00113   );
00114 
00115   /** Finds the end of the ball */
00116   bool findEndOfBall(
00117     const Image& image,
00118     const CameraInfo& bwCameraInfo,
00119     const ColorTable& colorTable,
00120     const BallPoint& start,
00121     const Vector2<int>& step,
00122     BallPoint& destination,
00123     int& countAmbiguous,
00124     int& countOrange,
00125     int& maxOrangePerLine,
00126     int& countPixel
00127     );
00128 
00129   /**
00130   * The function tries to calculate the ball percept by using the Levenberg-Marquardt
00131   * algorithm. The function fails if less than 3 points are available.
00132   * @return true if ball percept was created
00133   */
00134   bool createBallPerceptLevenbergMarquardt
00135   (
00136     const BallPointList& ballPoints,
00137     Vector2<int>& center,
00138     double& radius
00139   );
00140 
00141   /*
00142   * Check if a list of points is inside a given circle
00143   */
00144   bool checkIfPointsAreInsideBall(const BallPointList& ballPoints, Vector2<int>& center, double radius);
00145 
00146   /**
00147   * The function checks whether a ball percept is plausible and will add it if so.
00148   * @param image The image the ballpercept comes from.
00149   * @param bwCameraInfo Object containing camera parameters.
00150   * @param colorTable The colortable to be used
00151   * @param cameraMatrix The matrix of the camera of the image.
00152   * @param prevCameraMatrix The matrix of the camera of a previous image.
00153   * @param center The center of the ball.
00154   * @param radius The radius of the ball.
00155   * @param ballPercept The object the ball is added to.
00156   */
00157   void addBallPercept
00158   (
00159     const Image& image,
00160     const CameraInfo& bwCameraInfo,
00161     const ColorTable& colorTable,
00162     const CameraMatrix& cameraMatrix,
00163     const CameraMatrix& prevCameraMatrix,
00164     const Vector2<int>& center,
00165     double radius,
00166     BallPercept& ballPercept
00167   );  
00168 
00169   const ColorCorrector& colorCorrector;
00170 };
00171 
00172 #endif// __BallSpecialist_h_
00173 
00174 /*
00175 * $Log: GT2004BallSpecialist.h,v $
00176 * Revision 1.9  2004/09/09 11:37:39  wachter
00177 * - Fixed some more doxygen-errors
00178 *
00179 * Revision 1.8  2004/09/09 10:15:57  spranger
00180 * fixed doxygen-errors
00181 *
00182 * Revision 1.7  2004/07/09 14:04:38  mkunz
00183 * comments corrected
00184 *
00185 * Revision 1.6  2004/06/13 11:28:16  nistico
00186 * Post processing scan on small balls, scanning radially always starting
00187 * from the calculated canter, looking for percentage of orange.
00188 * Ghost balls on pink/yellow landmarks problem should be finally fixed now.
00189 *
00190 * Revision 1.5  2004/06/05 07:58:21  roefer
00191 * Compensation for motion distortions of images
00192 *
00193 * Revision 1.4  2004/05/27 19:38:26  loetzsch
00194 * compilation fixed
00195 *
00196 * Revision 1.3  2004/05/25 17:45:09  mkunz
00197 * parameters of calculation of oranges similarity tuned
00198 *
00199 * Revision 1.2  2004/05/25 10:09:49  mkunz
00200 * use global YCbCr-->RGB method
00201 *
00202 * Revision 1.1.1.1  2004/05/22 17:19:41  cvsadm
00203 * created new repository GT2004_WM
00204 *
00205 * Revision 1.2  2004/05/14 16:37:42  nistico
00206 * Ghost balls on landmark improvements:
00207 * -introduced ambiguous (pink, red, yellow) color check in ball recognition
00208 * -some parameter tuning
00209 *
00210 * Revision 1.1  2004/05/04 13:40:19  tim
00211 * added GT2004ImageProcessor
00212 *
00213 */

Generated on Thu Sep 23 19:57:28 2004 for GT2004 by doxygen 1.3.6