DownwardVision.C
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "BeoSub/IsolateColor.H"
00039 #include "DownwardVision.H"
00040 #include "GUI/DebugWin.H"
00041
00042
00043 DownwardVisionAgent::DownwardVisionAgent(OptionManager& mgr,
00044 nub::soft_ref<AgentManager> ama,
00045 const std::string& name):
00046 SensorAgent(mgr, ama, name)
00047 {
00048 itsPipeRecognizer.reset(new PipeRecognizer());
00049 itsFrameNumber = 0;
00050 }
00051
00052
00053
00054 bool DownwardVisionAgent::pickAndExecuteAnAction()
00055 {
00056
00057
00058
00059 uint fNum = itsAgentManager->getCurrentFrameNumber();
00060
00061 if(1)
00062 {
00063 itsFrameNumber = fNum;
00064 switch(itsCurrentMission->missionName)
00065 {
00066
00067 case Mission::FIRST_BIN:
00068 {
00069
00070 rutz::shared_ptr<Image<PixRGB<byte> > > currImg ( new Image<PixRGB<byte> > ((itsAgentManager->getCurrentDownwardImage())));
00071
00072
00073
00074
00075 lookForPipe(currImg, currImg);
00076
00077 break;
00078 }
00079
00080 case Mission::SECOND_BIN:
00081 {
00082 break;
00083 }
00084
00085 case Mission::GET_TREASURE:
00086 {
00087 break;
00088 }
00089 default:
00090 {
00091
00092 }
00093
00094 }
00095
00096
00097 SensorResult saliency = SensorResult(SensorResult::SALIENCY);
00098
00099
00100 SensorResult stereo = SensorResult(SensorResult::STEREO);
00101
00102 return true;
00103 }
00104
00105 return false;
00106
00107 }
00108
00109
00110
00111 void DownwardVisionAgent::runStereo()
00112 {
00113 Do("Running Stereo Vision");
00114 }
00115
00116 void DownwardVisionAgent::runSaliency()
00117 {
00118 Do("Running Saliency");
00119 }
00120
00121 void DownwardVisionAgent::lookForPipe(rutz::shared_ptr<Image<PixRGB<byte> > > segImg,
00122 rutz::shared_ptr<Image<PixRGB<byte> > > currImg)
00123 {
00124 Do("Looking for Pipe");
00125
00126
00127
00128 rutz::shared_ptr<SensorResult> pipe(new SensorResult(SensorResult::PIPE));
00129 pipe->setStatus(SensorResult::NOT_FOUND);
00130
00131 std::vector<LineSegment2D> pipelines = itsPipeRecognizer->getPipeLocation(segImg,
00132 currImg,
00133 PipeRecognizer::HOUGH);
00134
00135
00136 int minY = -1;
00137 int followLineIndex = -1;
00138
00139
00140 for(uint i = 0; i < pipelines.size(); i++)
00141 {
00142 LineSegment2D pipeline = pipelines[i];
00143
00144 if(pipeline.isValid())
00145 {
00146 Point2D<int> midpoint = (pipeline.point1() + pipeline.point2())/2;
00147
00148 if(midpoint.j < minY || minY == -1)
00149 {
00150 minY = midpoint.j;
00151 followLineIndex = i;
00152 }
00153 }
00154 }
00155
00156
00157 if(followLineIndex != -1)
00158 {
00159 LineSegment2D followLine = pipelines[followLineIndex];
00160 Point2D<int> midpoint = (followLine.point1() + followLine.point2())/2;
00161 Point2D<int> projPoint(Point2D<int>(0,0));
00162
00163 projPoint.i = (int)(midpoint.i+30*cos(followLine.angle()));
00164 projPoint.j = (int)(midpoint.j+30*sin(followLine.angle()));
00165
00166 drawLine(*currImg, midpoint, projPoint, PixRGB <byte> (255, 255,0), 3);
00167
00168 Point3D pipePos (midpoint.i,-1,midpoint.j);
00169 Angle pipeOri = Angle(followLine.angle());
00170
00171 pipe->setPosition(pipePos);
00172 pipe->setOrientation(pipeOri);
00173 pipe->setFrameNum(itsFrameNumber);
00174
00175
00176 pipe->setStatus(SensorResult::FOUND);
00177 itsAgentManager->updateSensorResult(pipe);
00178 }
00179
00180
00181 itsAgentManager->drawDownwardImage(currImg);
00182
00183 }
00184
00185
00186 void DownwardVisionAgent::lookForBin(rutz::shared_ptr<Image<byte> > segImg)
00187 {
00188 Do("Looking for Bin");
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213 }
00214
00215
00216 void DownwardVisionAgent::lookForCross(rutz::shared_ptr<Image<byte> > segImg)
00217 {
00218 Do("Looking for Cross");
00219
00220 }
00221
00222
00223
00224
00225
00226
00227