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

# Modules/ImageProcessor/ImageProcessorTools/GoalRecognizer.h

Go to the documentation of this file.

    00001 /**
    00002 * @file GoalRecognizer.h
    00003 *
    00004 * Definition of class GoalRecognizer
    00005 *
    00006 * @author <a href="mailto:juengel@informatik.hu-berlin.de">Matthias Juengel</a>
    00007 */
    00008
    00009 #ifndef __GoalRecognizer_h_
    00010 #define __GoalRecognizer_h_
    00011
    00012 #include "Representations/Perception/Image.h"
    00013 #include "Representations/Perception/CameraMatrix.h"
    00014 #include "Representations/Perception/ColorTable.h"
    00015 #include "Representations/Perception/ObstaclesPercept.h"
    00016 #include "Representations/Perception/LandmarksPercept.h"
    00017
    00018
    00019 #include "Tools/Math/Geometry.h"
    00020 #include "Tools/Debugging/DebugImages.h"
    00021
    00022 /**
    00023 * @class GoalRecognizer
    00024 *
    00025 * The goal recognizer recognizes the goals in the image.
    00026 *
    00027 * The recognizer scans horizontal lines in the image left to right.
    00028 * Indications for a goal are grouped and checked vertical.
    00029 *
    00030 * @author <a href="mailto:juengel@informatik.hu-berlin.de">Matthias Juengel</a>
    00031 */
    00032
    00033 class GoalRecognizer //: public ImageProcessorInterfaces
    00034 {
    00035 public:
    00036   GoalRecognizer(
    00037     const Image& image,
    00038     const CameraMatrix& cameraMatrix,
    00039     const ColorTable& colorTable,
    00040     ObstaclesPercept& obstaclesPercept,
    00041     LandmarksPercept& landmarksPercept
    00042     );
    00043
    00044   GoalRecognizer(
    00045     const Image& image,
    00046     const CameraMatrix& cameraMatrix,
    00047     const ColorTable& colorTable,
    00048     int goalIndicationAboveHorizon,
    00049     int goalIndicationBelowHorizon,
    00050     ObstaclesPercept& obstaclesPercept,
    00051     LandmarksPercept& landmarksPercept
    00052     );
    00053
    00054   ~GoalRecognizer();
    00055
    00056   void getGoalPercept(LandmarksPercept& landmarksPercept);
    00057
    00058   struct ColoredPartsCheck
    00059   {
    00060     Vector2<int> firstPoint;
    00061     Vector2<int> lastPoint;
    00062     int rangeOfColor;
    00063     int numberOfColoredPixels;
    00064
    00065     enum{maxNumberOfParts = 20};
    00066
    00067     int numberOfLargeParts;
    00068     int sizeOfLargePart[maxNumberOfParts];
    00069     Vector2<int> largePartBegin[maxNumberOfParts];
    00070     Vector2<int> largePartEnd[maxNumberOfParts];
    00071     Vector2<double> largePartBeginAngles[maxNumberOfParts];
    00072     Vector2<double> largePartEndAngles[maxNumberOfParts];
    00073     bool largePartBeginIsOnBorder[maxNumberOfParts];
    00074     bool largePartEndIsOnBorder[maxNumberOfParts];
    00075
    00076     ColoredPartsCheck()
    00077     {
    00078       numberOfLargeParts = 0;
    00079     }
    00080
    00081     bool determineLargePart(int size, bool beginIsOnBorder, bool endIsOnBorder, CameraMatrix cameraMatrix, CameraInfo cameraInfo)
    00082     {
    00083       bool foundLargePart = false;
    00084 //      if(numberOfColoredPixels > 3)
    00085       {
    00086         if(rangeOfColor > size)
    00087         {
    00088           sizeOfLargePart[numberOfLargeParts] = rangeOfColor;
    00089           largePartBegin[numberOfLargeParts].x = firstPoint.x;
    00090           largePartBegin[numberOfLargeParts].y = firstPoint.y;
    00091           largePartEnd[numberOfLargeParts].x = lastPoint.x;
    00092           largePartEnd[numberOfLargeParts].y = lastPoint.y;
    00093           largePartBeginIsOnBorder[numberOfLargeParts] = beginIsOnBorder;
    00094           largePartEndIsOnBorder[numberOfLargeParts] = endIsOnBorder;
    00095
    00096           Vector2<double> minAngles, maxAngles;
    00097           Geometry::calculateAnglesForPoint(largePartBegin[numberOfLargeParts], cameraMatrix, cameraInfo, largePartBeginAngles[numberOfLargeParts]);
    00098           Geometry::calculateAnglesForPoint(largePartEnd[numberOfLargeParts], cameraMatrix, cameraInfo, largePartEndAngles[numberOfLargeParts]);
    00099
    00100           numberOfLargeParts++;
    00101           foundLargePart = true;
    00102           LINE(imageProcessor_flagsAndGoals, firstPoint.x, firstPoint.y, lastPoint.x, lastPoint.y,
    00103             2, Drawings::ps_solid, Drawings::pink);
    00104         }
    00105
    00106         if(numberOfLargeParts >= maxNumberOfParts)
    00107         {
    00108           numberOfLargeParts = maxNumberOfParts-1;
    00109         }
    00110       }
    00111       return foundLargePart;
    00112     }
    00113   };
    00114
    00115 private:
    00116
    00117   /** Calculates the scan lines near the horizon for the goals */
    00118   void calculateScanLinesParallelToHorizon();
    00119
    00120   /** Calculates the scan lines near the horizon for the goals */
    00121   void calculateScanLinesParallelToHorizon(
    00122     int distanceAboveHorizon,
    00123     int distanceBelowHorizon,
    00124     int numberOfScanLines
    00125     );
    00126
    00127   /** Scans horizontal for goals */
    00128   void scanHorizontalForGoals();
    00129
    00130   /** Calculates the vertical scan lines for the goals */
    00131   void calculateVerticalGoalScanLines();
    00132
    00133   /** Scans vertical for goals */
    00134   void scanLinesForGoals();
    00135
    00136   DECLARE_DEBUG_IMAGE(imageProcessorGoals);
    00137
    00138   /** A reference to the image that is scanned for a goal */
    00139   const Image& image;
    00140
    00141   /** A reference to the camera matrix that describes position and rotation of the camera when the image was aquired */
    00142   const CameraMatrix& cameraMatrix;
    00143
    00144   /** A reference to the color table */
    00145   const ColorTable& colorTable;
    00146
    00147   int goalIndicationAboveHorizon;
    00148   int goalIndicationBelowHorizon;
    00149   bool useFixedScanLines;
    00150
    00151   /** A reference to the obstacles percept */
    00152   ObstaclesPercept& obstaclesPercept;
    00153
    00154   /** A reference to the obstacles percept */
    00155   LandmarksPercept& landmarksPercept;
    00156
    00157   /** The color class of the opponent goal */
    00158   colorClass colorOfOpponentGoal;
    00159
    00160   /** The color class of the own goal */
    00161   colorClass colorOfOwnGoal;
    00162
    00163   /** A representation of the horizon */
    00164   Geometry::Line horizonLine, verticalLine;
    00165
    00166   /** The number of horizontal scan lines */
    00167   int numberOfHorizontalScanLines;
    00168
    00169   enum{maxNumberOfHorizontalScanLines = 32};
    00170   enum{maxNumberOfGoalScanLines = 255};
    00171
    00172   /** representation of the left points of the horizontal scan lines */
    00173   Vector2<int> leftPoint[maxNumberOfHorizontalScanLines];
    00174
    00175   /** representation of the right points of the horizontal scan lines */
    00176   Vector2<int> rightPoint[maxNumberOfHorizontalScanLines];
    00177
    00178   /** the number of indications for goals */
    00179   int numberOfGoalIndications;
    00180
    00181   /** left point of an indications for a goal */
    00182   Vector2<int> goalIndicationLeft[maxNumberOfGoalScanLines];
    00183
    00184   /** left point of an indications for a goal */
    00185   Vector2<int> goalIndicationCenter[maxNumberOfGoalScanLines];
    00186
    00187   /** right point of an indication for a goal */
    00188   Vector2<int> goalIndicationRight[maxNumberOfGoalScanLines];
    00189
    00190   /** true if the left end of the goal indication is on the border of the image */
    00191   bool leftOfGoalIndicationIsOnBorder[maxNumberOfGoalScanLines];
    00192
    00193   /** true if the right end of the goal indication is on the border of the image */
    00194   bool rightOfGoalIndicationIsOnBorder[maxNumberOfGoalScanLines];
    00195
    00196   /** the color class of the goal indication */
    00197   colorClass colorOfGoalIndication[maxNumberOfGoalScanLines];
    00198
    00199   /** The number of vertical scan lines where a goal is searched*/
    00200   int numberOfGoalScanLines;
    00201
    00202   /** representation of the top points of the goal scan lines */
    00203   Vector2<int> topGoalPoint[maxNumberOfGoalScanLines];
    00204
    00205   /** representation of the bottom points of the goal scan lines */
    00206   Vector2<int> bottomGoalPoint[maxNumberOfGoalScanLines];
    00207
    00208   bool scanLineToCheckBestAngle[maxNumberOfGoalScanLines];
    00209
    00210   /** */
    00211   int indexOfGoalIndication[maxNumberOfGoalScanLines];
    00212
    00213   /** */
    00214   colorClass colorOfGoalScanLine[maxNumberOfGoalScanLines];
    00215
    00216 };
    00217
    00218 #endif