salBeeMain.C

Go to the documentation of this file.
00001 /*!@file SeaBee/salBeeMain.C Main dispatcher  */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // University of Southern California (USC) and the iLab at USC.         //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Lior Elazary <elazary@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/SeaBee/salBeeMain.C $
00035 // $Id: salBeeMain.C 10794 2009-02-08 06:21:09Z itti $
00036 //
00037 
00038 //
00039 #include "Component/ModelManager.H"
00040 #include "Devices/DeviceOpts.H"
00041 #include "Media/FrameSeries.H"
00042 #include "Media/MediaOpts.H"
00043 #include "Image/ShapeOps.H"
00044 #include "Image/MathOps.H"
00045 #include "SeaBee/SubController.H"
00046 #include "SeaBee/SubGUI.H"
00047 
00048 #include "Devices/DeviceOpts.H"
00049 #include "GUI/XWinManaged.H"
00050 #include "Raster/GenericFrame.H"
00051 #include "Raster/Raster.H"
00052 #include "Component/ModelManager.H"
00053 #include "Devices/DeviceOpts.H"
00054 #include "GUI/XWindow.H"
00055 #include "Image/DrawOps.H"
00056 #include "Image/CutPaste.H"
00057 #include "Image/Image.H"
00058 #include "Image/Pixels.H"
00059 #include "Image/MathOps.H"
00060 #include "Neuro/EnvVisualCortex.H"
00061 #include "Media/FrameSeries.H"
00062 #include "Media/MediaOpts.H"
00063 #include "Transport/FrameInfo.H"
00064 #include "Raster/GenericFrame.H"
00065 #include "Raster/Raster.H"
00066 #include "Util/Timer.H"
00067 #include "Util/log.H"
00068 #include "Util/MathFunctions.H"
00069 #include "Neuro/EnvVisualCortex.H"
00070 #include "Util/Angle.H"
00071 
00072 int main(int argc, const char **argv)
00073 {
00074         int compMode = false;
00075 
00076         // Instantiate a ModelManager:
00077         ModelManager *mgr = new ModelManager("USC BeoSub");
00078 
00079         nub::soft_ref<InputFrameSeries> ifs(new InputFrameSeries(*mgr));
00080         mgr->addSubComponent(ifs);
00081 
00082         nub::soft_ref<OutputFrameSeries> ofs(new OutputFrameSeries(*mgr));
00083         mgr->addSubComponent(ofs);
00084 
00085         nub::soft_ref<SubController> subController(new SubController(*mgr));
00086         mgr->addSubComponent(subController);
00087 
00088         nub::soft_ref<SubGUI> subGUI(new SubGUI(*mgr));
00089         mgr->addSubComponent(subGUI);
00090 
00091         nub::ref<EnvVisualCortex> evc(new EnvVisualCortex(*mgr));
00092         mgr->addSubComponent(evc);
00093 
00094         mgr->exportOptions(MC_RECURSE);
00095 
00096         mgr->setOptionValString(&OPT_InputFrameSource, "V4L2");
00097         mgr->setOptionValString(&OPT_FrameGrabberMode, "YUYV");
00098         mgr->setOptionValString(&OPT_FrameGrabberDims, "1024x576");
00099         mgr->setOptionValString(&OPT_FrameGrabberByteSwap, "no");
00100         mgr->setOptionValString(&OPT_FrameGrabberFPS, "30");
00101 
00102 
00103         // Parse command-line:
00104         if (mgr->parseCommandLine(argc, argv, "<compMode>", 0, 1) == false) return(1);
00105 
00106         if (mgr->numExtraArgs() &&
00107                         mgr->getExtraArg(0) == "compMode")
00108                                         compMode = true;
00109 
00110 
00111 
00112 
00113         // do post-command-line configs:
00114         //Dims imageDims = ifs->peekDims();
00115 
00116         // let's get all our ModelComponent instances started:
00117         mgr->start();
00118 
00119         int smap_level = evc->getMapLevel();
00120         //start streaming
00121         ifs->startStream();
00122 
00123 
00124         //setup gui for subController
00125 
00126         subController->setMotorsOn(false);
00127         if (!compMode)
00128         {
00129                 subGUI->startThread(ofs);
00130                 subGUI->setupGUI(subController.get(), true);
00131                 subGUI->addMeter(subController->getIntPressurePtr(),
00132                                 "Int Pressure", 500, PixRGB<byte>(255, 0, 0));
00133                 subGUI->addMeter(subController->getHeadingPtr(),
00134                                 "Heading", 360, PixRGB<byte>(192, 255, 0));
00135                 subGUI->addMeter(subController->getPitchPtr(),
00136                                 "Pitch", 256, PixRGB<byte>(192, 255, 0));
00137                 subGUI->addMeter(subController->getRollPtr(),
00138                                 "Roll", 256, PixRGB<byte>(192, 255, 0));
00139                 subGUI->addMeter(subController->getDepthPtr(),
00140                                 "Depth", 300, PixRGB<byte>(192, 255, 0));
00141 
00142                 subGUI->addMeter(subController->getThruster_Up_Left_Ptr(),
00143                                 "Motor_Up_Left", -100, PixRGB<byte>(0, 255, 0));
00144                 subGUI->addMeter(subController->getThruster_Up_Right_Ptr(),
00145                                 "Motor_Up_Right", -100, PixRGB<byte>(0, 255, 0));
00146                 subGUI->addMeter(subController->getThruster_Up_Back_Ptr(),
00147                                 "Motor_Up_Back", -100, PixRGB<byte>(0, 255, 0));
00148                 subGUI->addMeter(subController->getThruster_Fwd_Left_Ptr(),
00149                                 "Motor_Fwd_Left", -100, PixRGB<byte>(0, 255, 0));
00150                 subGUI->addMeter(subController->getThruster_Fwd_Right_Ptr(),
00151                                 "Motor_Fwd_Right", -100, PixRGB<byte>(0, 255, 0));
00152 
00153 
00154                 subGUI->addImage(subController->getSubImagePtr());
00155                 subGUI->addImage(subController->getPIDImagePtr());
00156         }
00157 
00158         subController->setSpeed(50);
00159         while(1)
00160         {
00161                 const FrameState is = ifs->updateNext();
00162                 if (is == FRAME_COMPLETE)
00163                         break;
00164 
00165                 //grab the images
00166                 GenericFrame input = ifs->readFrame();
00167                 if (!input.initialized())
00168                         break;
00169                 Image<PixRGB<byte> > frontImg = rescale(input.asRgb(), 320, 280);
00170                 evc->input(frontImg);
00171                 Image<float> vcxmap = evc->getVCXmap();
00172                 Point2D<int> maxPos; float maxVal;
00173                 findMax(vcxmap, maxPos, maxVal);
00174                 LINFO("SalVal %f", maxVal);
00175 
00176                 if (maxVal > 100)
00177                 {
00178 
00179                         int xerr = (maxPos.i-(vcxmap.getWidth()/2));
00180                         int yerr = (maxPos.j-(vcxmap.getHeight()/2));
00181 
00182                         int desiredHeading = xerr*3;
00183                         int desiredDepth = yerr*3;
00184 
00185                         subController->setHeading(
00186                                         subController->getHeading()
00187                                                + desiredHeading);
00188 
00189                         subController->setDepth(
00190                                         subController->getDepth()
00191                                                + desiredDepth);
00192 
00193                 }
00194 
00195 
00196                 inplaceNormalize(vcxmap, 0.0F, 255.0F);
00197                 Image<PixRGB<byte> > salDisp = rescale(vcxmap,frontImg.getDims()) ;
00198                 drawCircle(frontImg,
00199                                        Point2D<int>(maxPos.i<<smap_level,
00200                                                maxPos.j<<smap_level),
00201                                 30,
00202                                 PixRGB<byte>(0,255,0));
00203 
00204                 ofs->writeRGB(frontImg, "input", FrameInfo("Copy of input", SRC_POS));
00205                 ofs->writeRGB(salDisp, "saliency", FrameInfo("Saliency", SRC_POS));
00206 
00207         }
00208 
00209 
00210         // stop all our ModelComponents
00211         mgr->stop();
00212 
00213         // all done!
00214         return 0;
00215 }
00216 
Generated on Sun May 8 08:42:14 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3