DownwardVision.C

Go to the documentation of this file.
00001 /*!@file SeaBee/DownwardVision.C Downward Vision Agent                  */
00002 // //////////////////////////////////////////////////////////////////// //
00003 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00004 // University of Southern California (USC) and the iLab at USC.         //
00005 // See http://iLab.usc.edu for information about this project.          //
00006 // //////////////////////////////////////////////////////////////////// //
00007 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00008 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00009 // in Visual Environments, and Applications'' by Christof Koch and      //
00010 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00011 // pending; application number 09/912,225 filed July 23, 2001; see      //
00012 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00013 // //////////////////////////////////////////////////////////////////// //
00014 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00015 //                                                                      //
00016 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00017 // redistribute it and/or modify it under the terms of the GNU General  //
00018 // Public License as published by the Free Software Foundation; either  //
00019 // version 2 of the License, or (at your option) any later version.     //
00020 //                                                                      //
00021 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00022 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00023 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00024 // PURPOSE.  See the GNU General Public License for more details.       //
00025 //                                                                      //
00026 // You should have received a copy of the GNU General Public License    //
00027 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00028 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00029 // Boston, MA 02111-1307 USA.                                           //
00030 // //////////////////////////////////////////////////////////////////// //
00031 //
00032 // Primary maintainer for this file: Michael Montalbo <montalbo@usc.edu>
00033 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/SeaBee/DownwardVision.C $
00034 // $Id: DownwardVision.C 10794 2009-02-08 06:21:09Z itti $
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 //Scheduler
00054 bool DownwardVisionAgent::pickAndExecuteAnAction()
00055 {
00056   //  bool lookedForObject = false;
00057   //itsCameraImage = itsAgentManager->getCurrentImage();
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           //rutz::shared_ptr<Image<byte> > segImg(new Image<byte>(320,240, ZEROS));
00070           rutz::shared_ptr<Image<PixRGB<byte> > > currImg ( new Image<PixRGB<byte> > ((itsAgentManager->getCurrentDownwardImage())));
00071 
00072           //          SHOWIMG(*currImg);
00073           //          isolateOrange(*currImg,*segImg);
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           //        LINFO("Uknown mission: %d",itsCurrentMission->missionName);
00092         }
00093 
00094       }
00095 
00096 
00097     SensorResult saliency = SensorResult(SensorResult::SALIENCY);
00098     //  runSaliency(saliency);
00099 
00100     SensorResult stereo = SensorResult(SensorResult::STEREO);
00101     //  runStereo(stereo);
00102     return true;
00103   }
00104 
00105   return false;
00106 
00107 }
00108 
00109 // ######################################################################
00110 //Actions
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   //  rutz::shared_ptr<Image<PixRGB<byte> > > outputImage(new Image<PixRGB<byte> >(320,240, ZEROS));
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; //minimum midpoint y coordinate found
00137   int followLineIndex = -1; //index of pipeline with minimum y coordinate
00138 
00139   //iterates through pipelines and finds the topmost one in the image
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   //if we found a pipeline
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   //  itsAgentManager->pushResult(s);
00191 
00192 //   if(j.status == NOT_STARTED) { j.status = IN_PROGRESS; }
00193 
00194 //   DataType jobDataType = j.dataType;
00195 //   rutz::shared_ptr<SensorResult> jobSensorResult = j.sensorResult;
00196 
00197 //   bool isFound = false;
00198 
00199 // //   std::vector<LineSegment2D> lines = getHoughLines(itsCameraImage, outputImage);
00200 
00201 //   if(jobDataType == POSITION)
00202 //     {
00203 //       Do("Looking for bin center");
00204 // //       Point2D<int> binCenter = binRecognizer->getBinCenter(lines);
00205 // //       if(pipeCenter.isValid())
00206 // //         {
00207 //           isFound = true;
00208 // //           jobSensorResult->setPosition(Point3D(binCenter.i, binCenter.j, -1));
00209 // //         }
00210 //     }
00211 
00212 //   sensorResultUpdate(jobSensorResult, jobDataType, isFound);
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 /* So things look consistent in everyone's emacs... */
00225 /* Local Variables: */
00226 /* indent-tabs-mode: nil */
00227 /* End: */
Generated on Sun May 8 08:40:16 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3