test-roadShape.C

Go to the documentation of this file.
00001 /*!@file Beobot/test-roadShape.C */
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; filed July 23, 2001, following provisional applications     //
00013 // No. 60/274,674 filed March 8, 2001 and 60/288,724 filed May 4, 2001).//
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: Laurent Itti <itti@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Beobot/test-roadShape.C $
00035 // $Id: test-roadShape.C 14376 2011-01-11 02:44:34Z pez $
00036 //
00037 
00038 //!To Display frames and associated interpretation of MetaData
00039 
00040 #include "GUI/XWindow.H"
00041 #include "Image/CutPaste.H"  // for inplacePaste()
00042 #include "Image/DrawOps.H"
00043 #include "Image/Image.H"
00044 #include "Image/Pixels.H"
00045 #include "Raster/Raster.H"
00046 
00047 #include <cmath>
00048 #include <signal.h>
00049 #include <stdlib.h>
00050 #include <time.h>
00051 #include <unistd.h>
00052 
00053 namespace
00054 {
00055   //! Metadata information (typically obtained from GPS)
00056   class MetaData
00057   {
00058   public:
00059     //! Constructor
00060     MetaData();
00061 
00062     //! Constructor
00063     MetaData( const MetaData& m );
00064 
00065     //! Constructor
00066     MetaData( std::string s );
00067 
00068     //! Parse from string
00069     void parseMetaData( std::string s );
00070 
00071     //! Access function
00072     float getAccel() const;
00073 
00074     //! Access function
00075     float getSteer() const;
00076 
00077     //! Access function
00078     float getLat() const;
00079 
00080     //! Access function
00081     float getLon() const;
00082 
00083     //! Access function
00084     float getEV() const;
00085 
00086     //! Access function
00087     float getNV() const;
00088 
00089     //protected:
00090     float accel; //!< Acceleration
00091     float steer; //!< Steering
00092     float lat;   //!< Latitude
00093     float lon;   //!< Longitude
00094     float ev;    //!< Velocity in east direction
00095     float nv;    //!< Velocity in north direction
00096   };
00097 
00098   MetaData::MetaData() :
00099     accel(0), steer(0), lat(0), lon(0), ev(0), nv(0)
00100   { }
00101 
00102   MetaData::MetaData( const MetaData& m ) :
00103     accel( m.accel ), steer( m.steer ), lat( m.lat ), lon( m.lon),
00104     ev( m.ev ), nv( m.nv )
00105   { }
00106 
00107   MetaData::MetaData( std::string s ) :
00108     accel(0), steer(0), lat(0), lon(0), ev(0), nv(0)
00109   {
00110     parseMetaData( s );
00111   }
00112 
00113   void MetaData::parseMetaData( std::string s )
00114   {
00115     std::string temp = "";
00116     int space;
00117     while( ( space = s.find( " ", 0 ) ) != int(std::string::npos) )
00118       {
00119         temp = s.substr( 0, space );
00120         s = s.substr( space, s.length() - space );
00121 
00122         if( temp.find( "ACCEL:", 0 ) != std::string::npos )
00123           accel = atof( temp.c_str() );
00124         if( temp.find("STEER:", 0) != std::string::npos )
00125           steer = atof( temp.c_str() );
00126         if( temp.find("LAT:", 0 ) != std::string::npos )
00127           lat = atof( temp.c_str() );
00128         if( temp.find("LON:", 0 ) != std::string::npos )
00129           lon = atof( temp.c_str() );
00130         if( temp.find("EV:", 0) != std::string::npos )
00131           ev = atof( temp.c_str() );
00132         if( temp.find("NV:", 0) != std::string::npos )
00133           nv = atof( temp.c_str() );
00134       }
00135   }
00136 
00137   float MetaData::getAccel() const
00138   { return accel; }
00139 
00140   float MetaData::getSteer() const
00141   { return steer; }
00142 
00143   float MetaData::getLat() const
00144   { return lat; }
00145 
00146   float MetaData::getLon() const
00147   { return lon; }
00148 
00149   float MetaData::getEV() const
00150   { return ev; }
00151 
00152   float MetaData::getNV() const
00153   { return nv; }
00154 }
00155 
00156 // ######################################################################
00157 int main(int argc, char **argv)
00158 {
00159   initRandomNumbers();
00160 
00161   int32 frame;
00162 
00163   int initFrame;
00164   char imageNameBase[100];
00165 
00166   // command line help
00167   if( argc >= 2 ) strcpy( imageNameBase, argv[1] );
00168   else LFATAL("arguments = dir/ [initFrame]");
00169 
00170   if( argc >= 3 ) initFrame = atoi( argv[2] );
00171   else initFrame = 0;
00172 
00173   Image< PixRGB<byte> > col_image =
00174     Raster::ReadRGB(sformat("%sframe%06d.ppm", imageNameBase, initFrame));
00175 
00176   //Here we are assuming all of the images will have the same dimensions
00177   const int HEIGHT = col_image.getHeight();
00178   const int WIDTH = col_image.getWidth();
00179 
00180   //Points dividing the window into image sized segments [3x3],
00181   //Based on image size
00182   Point2D<int> up_left(0, 0);
00183   Point2D<int> up_mid( WIDTH, 0 );
00184   //Point2D<int> up_right( WIDTH*2, 0 );
00185   //Point2D<int> mid_left(0, HEIGHT );
00186   //Point2D<int> mid_mid( WIDTH, HEIGHT );
00187   //Point2D<int> mid_right( WIDTH*2, HEIGHT );
00188   //Point2D<int> low_left(0, HEIGHT*2 );
00189   //Point2D<int> low_mid( WIDTH, HEIGHT*2 );
00190   //Point2D<int> low_right( WIDTH*2, HEIGHT*2 );
00191 
00192   //Acceleration representation rectangle
00193   Rectangle accel;
00194 
00195   //Steering represenation rectangle
00196   Rectangle steer;
00197 
00198 
00199   Image< PixRGB<byte> > final_image( WIDTH*2, HEIGHT, ZEROS );
00200 
00201   // this is to show the final composite image
00202   XWindow xwindow( Dims(WIDTH*2, HEIGHT*2) );
00203 
00204 
00205   // initialization of the beast
00206 
00207   //This image will show the steering and acceleration vector representations
00208   //Image< PixRGB<byte> > radioImage(  WIDTH, HEIGHT, ZEROS );
00209   Image< PixRGB<byte> > radioImage = Raster::ReadRGB("speedo.ppm");
00210 
00211   //Image< PixRGB<byte> > clear( WIDTH, HEIGHT, ZEROS );
00212 
00213   MetaData mData;
00214 
00215   // big loop
00216   for(frame = initFrame; ; frame+=1)
00217     {
00218       // read current frame
00219       col_image = Raster::ReadRGB(sformat("%sframe%06d.ppm",
00220                                           imageNameBase, frame));
00221       // and display it for debug
00222 
00223       inplacePaste( final_image, col_image, up_left );
00224 
00225       //now we want to create some sort of representaiton of the speed
00226       //And direction we are trying to go
00227 
00228       //Read in the MetaData from the image
00229       mData = MetaData(Raster::getImageComments
00230                        (sformat("%sframe%06d.ppm",
00231                                 imageNameBase, frame)));
00232 
00233       //Since accel is nicely between -1 and 1, we can simply multiply it
00234       //by half of the image height to get an offset for drawing our acceleration
00235       //Rectangle.
00236 
00237       int vert = (int) 0;//(mData.accel * (HEIGHT/2));
00238       int hori = (int) 0;//(mData.steer * (WIDTH/2));
00239 
00240       LINFO("VERT: %d\nHORI: %d", vert, hori);
00241       if( vert == 0 )
00242         vert = 1;
00243       if( hori == 0 )
00244         hori = 1;
00245 
00246 
00247       if (frame > 100) {
00248         vert = 30;
00249         hori = 30;
00250       }
00251 
00252       //Set the acceleration rectangle
00253       if( vert < 0 )
00254         {
00255           LINFO("uu:%d ll:%d bb:%d rr:%d", HEIGHT + vert, 0, HEIGHT / 2, 10);
00256           accel = Rectangle::tlbrI( HEIGHT / 2, 0,
00257                                    HEIGHT / 2 - vert, 10 );
00258         }
00259       else
00260         {
00261           LINFO("uu:%d ll:%d bb:%d rr:%d", HEIGHT / 2, 0, HEIGHT + vert, 10);
00262           accel = Rectangle::tlbrI( HEIGHT / 2 - vert, 0,
00263                                    HEIGHT / 2, 10 );
00264         }
00265 
00266       //Set the steering rectangle
00267       if( hori > 0 )
00268         {
00269           LINFO("uu:%d ll:%d bb:%d rr:%d", HEIGHT - 10, WIDTH / 2, HEIGHT, WIDTH / 2 + hori);
00270           steer = Rectangle::tlbrI( HEIGHT - 11, WIDTH / 2,
00271                                    HEIGHT - 1, WIDTH / 2 + hori );
00272         }
00273       else
00274         {
00275           LINFO("uu:%d ll:%d bb:%d rr:%d", HEIGHT - 10, WIDTH / 2 + hori,
00276                 HEIGHT, WIDTH / 2 );
00277           steer = Rectangle::tlbrI( HEIGHT - 11, WIDTH / 2 + hori,
00278                                    HEIGHT - 1, WIDTH / 2 );
00279         }
00280 
00281       PixRGB<byte> whitePixel(255,36,255);
00282 
00283       //radioImage.clear( blackPixel );
00284 
00285       drawRect( radioImage, accel, whitePixel, 1 );
00286       drawRect( radioImage, steer, whitePixel, 1 );
00287 
00288       //Point2D<int> p1( WIDTH / 2, HEIGHT / 2 );
00289       Point2D<int> p1( WIDTH / 2, HEIGHT );
00290       Point2D<int> p2( WIDTH / 2 + hori, HEIGHT / 2 - vert );
00291 
00292       drawArrow(radioImage, p1, p2, whitePixel, 2);
00293 
00294 
00295       inplacePaste( final_image, radioImage, up_mid );
00296 
00297       //drawImage( xwindow, final_image );
00298 
00299       LINFO("Writing: %smovie/frame%06d.ppm", imageNameBase, frame);
00300       Raster::WriteRGB( final_image,
00301                         sformat("%smovie/frame%06d.ppm", imageNameBase, frame) );
00302     }
00303 
00304   LINFO( "END OF test-MetaData" );
00305   exit(0);
00306 }
00307 
00308 // ######################################################################
00309 /* So things look consistent in everyone's emacs... */
00310 /* Local Variables: */
00311 /* indent-tabs-mode: nil */
00312 /* End: */
Generated on Sun May 8 08:40:15 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3