00001
00002
00003
00004
00005
00006
00007
00008 #include "RasterImageProcessor.h"
00009 #include "Tools/Math/Common.h"
00010 #include "Tools/Debugging/GenericDebugData.h"
00011 #include "Tools/FieldDimensions.h"
00012 #include "Tools/RingBuffer.h"
00013 #include "Representations/Perception/ColorTable64.h"
00014 #include "RDefaultStrategy.h"
00015
00016 #include <time.h>
00017
00018 using namespace std;
00019
00020
00021 RasterImageProcessor::RasterImageProcessor(const ImageProcessorInterfaces& interfaces)
00022 : ImageProcessor(interfaces),
00023 corrector(),
00024 edgeDetector(10)
00025 {
00026 for (int i=0;i < maxRasterSpecialists; i++)
00027 specials[i] = NULL;
00028
00029 minX = 0;
00030 minY = 0;
00031 maxX = image.cameraInfo.resolutionWidth -1;
00032 maxY = image.cameraInfo.resolutionHeight -1;
00033
00034
00035 strategy = new RDefaultStrategy(*this);
00036 waitingStrategy = NULL;
00037
00038
00039 }
00040
00041 RasterImageProcessor::~RasterImageProcessor()
00042 {
00043 delete strategy;
00044 }
00045
00046 void RasterImageProcessor::execute()
00047 {
00048
00049
00050 INIT_DEBUG_IMAGE(imageProcessorBall,image);
00051 INIT_DEBUG_IMAGE(imageProcessorObstacles,image);
00052 INIT_DEBUG_IMAGE(imageProcessorFlagsAndGoals, image);
00053 INIT_DEBUG_IMAGE(imageProcessorGround, image);
00054 INIT_DEBUG_IMAGE(imageProcessorGeneral, image);
00055
00056
00057
00058
00059
00060
00061
00062
00063 init();
00064
00065 strategy->execute();
00066
00067
00068
00069
00070
00071
00072
00073
00074 DEBUG_DRAWING_FINISHED(imageProcessor_general);
00075 DEBUG_DRAWING_FINISHED(imageProcessor_ball1);
00076 DEBUG_DRAWING_FINISHED(imageProcessor_ball2);
00077 DEBUG_DRAWING_FINISHED(imageProcessor_ball3);
00078 DEBUG_DRAWING_FINISHED(imageProcessor_obstacles);
00079 DEBUG_DRAWING_FINISHED(imageProcessor_ground);
00080 DEBUG_DRAWING_FINISHED(imageProcessor_flagsAndGoals);
00081 };
00082
00083 bool RasterImageProcessor::handleMessage(InMessage &message)
00084 {
00085
00086
00087 return false;
00088 };
00089
00090 RasterSpecialist *RasterImageProcessor::getSpecialist(int type)
00091 {
00092 return specials[type];
00093 }
00094
00095 void RasterImageProcessor::setSpecialist(RasterSpecialist *specialist)
00096 {
00097 int type = specialist->getType();
00098 if (specials[type]!=0) delete specials[type];
00099 specials[type] = specialist;
00100
00101 }
00102
00103 void RasterImageProcessor::removeSpecialist(int type)
00104 {
00105 delete specials[type];
00106 specials[type] = NULL;
00107 }
00108
00109
00110 void RasterImageProcessor::changeStrategy(RasterStrategy &newStrategy)
00111 {
00112 waitingStrategy = &newStrategy;
00113
00114 }
00115
00116 void RasterImageProcessor::init()
00117 {
00118 if (waitingStrategy != NULL) {
00119 delete strategy;
00120 strategy = waitingStrategy;
00121 waitingStrategy = NULL;
00122 }
00123
00124 strategy->init();
00125
00126
00127
00128 GENERATE_DEBUG_IMAGE(segmentedImage1,
00129 colorTable.generateColorClassImage(image, segmentedImage1ColorClassImage));
00130
00131 SEND_DEBUG_COLOR_CLASS_IMAGE(segmentedImage1);
00132
00133
00134 landmarksPercept.reset(image.frameNumber);
00135 linesPercept.reset(image.frameNumber);
00136 ballPercept.reset(image.frameNumber);
00137 playersPercept.reset(image.frameNumber);
00138 obstaclesPercept.reset(image.frameNumber);
00139
00140 landmarksPercept.cameraOffset = cameraMatrix.translation;
00141
00142 horizon = Geometry::calculateHorizon(cameraMatrix, image.cameraInfo);
00143
00144 LINE(imageProcessor_general,
00145 (int)(horizon.base.x - 120 * horizon.direction.x ), (int)(horizon.base.y - 120 * horizon.direction.y),
00146 (int)(horizon.base.x + 120 * horizon.direction.x), (int)(horizon.base.y + 120 * horizon.direction.y),
00147 1, Drawings::ps_solid, Drawings::white );
00148
00149
00150 }
00151
00152 void RasterImageProcessor::addFlag(Vector2<double>& left,Vector2<double>& right,
00153 Vector2<double>& top, Vector2<double>& bottom,Flag::FlagType type){
00154 DOT(imageProcessor_flagsAndGoals, right.x, right.y,
00155 Drawings::red, Drawings::black);
00156 DOT(imageProcessor_flagsAndGoals, left.x, left.y,
00157 Drawings::green, Drawings::black);
00158
00159 bool topOnBorder = !isValidPoint(top);
00160 bool bottomOnBorder = !isValidPoint(bottom);
00161 bool leftOnBorder = !isValidPoint(left);
00162 bool rightOnBorder = !isValidPoint(right);
00163
00164 double factor = image.cameraInfo.resolutionWidth / 2 / tan(image.cameraInfo.openingAngleWidth / 2);
00165 int flip = getPlayer().getTeamColor() == Player::blue ? -1 : 1;
00166
00167 Vector3<double> vectorToLeft(factor,
00168 image.cameraInfo.resolutionWidth / 2 - left.x,
00169 image.cameraInfo.resolutionHeight / 2 - left.y);
00170 Vector3<double> vectorToRight(factor,
00171 image.cameraInfo.resolutionWidth / 2 - right.x,
00172 image.cameraInfo.resolutionHeight / 2 - right.y);
00173 Vector3<double> vectorToTop(factor,
00174 image.cameraInfo.resolutionWidth / 2 - top.x,
00175 image.cameraInfo.resolutionHeight / 2 - top.y);
00176 Vector3<double> vectorToBottom(factor,
00177 image.cameraInfo.resolutionWidth / 2 - bottom.x,
00178 image.cameraInfo.resolutionHeight / 2 - bottom.y);
00179
00180 Vector3<double>
00181 vectorToLeftWorld = cameraMatrix.rotation * vectorToLeft,
00182 vectorToRightWorld = cameraMatrix.rotation * vectorToRight,
00183 vectorToTopWorld = cameraMatrix.rotation * vectorToTop,
00184 vectorToBottomWorld = cameraMatrix.rotation * vectorToBottom;
00185
00186 double
00187 leftAngle = atan2(vectorToLeftWorld.y,vectorToLeftWorld.x),
00188 rightAngle = atan2(vectorToRightWorld.y,vectorToRightWorld.x),
00189 topAngle = atan2(vectorToTopWorld.z,sqrt((double)sqr(vectorToTopWorld.x) + sqr(vectorToTopWorld.y)) ),
00190 bottomAngle = atan2(vectorToBottomWorld.z,sqrt((double)sqr(vectorToBottomWorld.x) + sqr(vectorToBottomWorld.y)) );
00191
00192
00193 Vector2<double>flagPosition;
00194
00195 switch (type)
00196 {
00197 case Flag::pinkAboveYellow:
00198 flagPosition.x = xPosBackFlags * flip;
00199 flagPosition.y = yPosRightFlags * flip;
00200 break;
00201 case Flag::pinkAboveSkyblue:
00202 flagPosition.x = xPosFrontFlags * flip;
00203 flagPosition.y = yPosRightFlags * flip;
00204 break;
00205 case Flag::yellowAbovePink:
00206 flagPosition.x = xPosBackFlags * flip;
00207 flagPosition.y = yPosLeftFlags * flip;
00208 break;
00209 case Flag::skyblueAbovePink:
00210 flagPosition.x = xPosFrontFlags * flip;
00211 flagPosition.y = yPosLeftFlags * flip;
00212 break;
00213 }
00214
00215 Vector2<double> centerAngle;
00216 ConditionalBoundary boundary;
00217
00218 boundary.addX(leftAngle,leftOnBorder);
00219 boundary.addX(rightAngle,rightOnBorder);
00220 boundary.addY(topAngle,topOnBorder);
00221 boundary.addY(bottomAngle,bottomOnBorder);
00222 landmarksPercept.addFlag(type, flagPosition, boundary);
00223 }
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333