test-keyboardGrab.C

Go to the documentation of this file.
00001 /*!@file Beobot/test-keyboardGrab.C Keyboard-controlled camera motion   */
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: Laurent Itti <itti@usc.edu>
00033 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Beobot/test-keyboardGrab.C $
00034 // $Id: test-keyboardGrab.C 6795 2006-06-29 20:45:32Z rjpeters $
00035 //
00036 
00037 #include "Component/ModelManager.H"
00038 #include "Devices/FrameGrabberConfigurator.H"
00039 #include "Devices/KeyBoard.H"
00040 #include "Devices/ssc.H"
00041 #include "GUI/XWindow.H"
00042 #include "Image/Image.H"
00043 #include "Image/Pixels.H"
00044 #include "Transport/FrameIstream.H"
00045 #include "Util/Timer.H"
00046 #include "Util/Types.H"
00047 #include "Util/log.H"
00048 
00049 #include <cstdio>
00050 #include <cstdlib>
00051 #include <cstring>
00052 
00053 // speed and steering servo number
00054 #define SP_SERVO_N    0
00055 #define ST_SERVO_N    1
00056 #define NAVG 20
00057 
00058 // ######################################################################
00059 /*! This simple executable tests video frame grabbing through the
00060   video4linux driver (see V4Lgrabber.H) or the IEEE1394 (firewire)
00061   grabber (see IEEE1394grabber.H). Selection of the grabber type is
00062   made via the --fg-type=XX command-line option. */
00063 int main(const int argc, const char **argv)
00064 {
00065   // instantiate a model manager:
00066   ModelManager manager("Frame Grabber Tester");
00067 
00068   // Instantiate our various ModelComponents:
00069   nub::soft_ref<FrameGrabberConfigurator>
00070     gbc(new FrameGrabberConfigurator(manager));
00071   manager.addSubComponent(gbc);
00072   nub::soft_ref<SSC> ssc(new SSC(manager));
00073   manager.addSubComponent(ssc);
00074 
00075   // Parse command-line:
00076   if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);
00077 
00078   // do post-command-line configs:
00079   nub::soft_ref<FrameIstream> gb = gbc->getFrameGrabber();
00080   if (gb.isInvalid())
00081     LFATAL("You need to select a frame grabber type via the "
00082            "--fg-type=XX command-line option for this program "
00083            "to be useful");
00084 
00085   // let's get all our ModelComponent instances started:
00086   manager.start();
00087 
00088   // instantiate a KeyBoard
00089   KeyBoard kb;
00090 
00091   // get ready for main loop:
00092   XWindow win(gb->peekDims(), -1, -1, "test-grab window");
00093   Timer tim; uint64 t[NAVG]; int frame = 0;
00094 
00095   while(1) {
00096     switch( kb.getKey( false ) )
00097       {
00098       case KBD_KEY1:
00099         if( ssc->getPosition(ST_SERVO_N) < 0.95f )
00100           ssc->move(ST_SERVO_N, ssc->getPosition(ST_SERVO_N) + 0.05f );
00101         break;
00102       case KBD_KEY2:
00103         if( ssc->getPosition(ST_SERVO_N) > -0.95f )
00104           ssc->move(ST_SERVO_N, ssc->getPosition(ST_SERVO_N) - 0.05f );
00105         break;
00106       case KBD_KEY3:
00107         if( ssc->getPosition(SP_SERVO_N) > -0.95f )
00108           ssc->move(SP_SERVO_N, ssc->getPosition(SP_SERVO_N) - 0.05f );
00109         break;
00110       case KBD_KEY5:
00111         if( ssc->getPosition(SP_SERVO_N) < 0.95f )
00112           ssc->move(SP_SERVO_N, ssc->getPosition(SP_SERVO_N) + 0.05f );
00113       default:
00114         break;
00115       }
00116     tim.reset();
00117 
00118     Image< PixRGB<byte> > ima = gb->readRGB();
00119 
00120     uint64 t0 = tim.get();  // to measure display time
00121     win.drawImage(ima);
00122     t[frame % NAVG] = tim.get();
00123     t0 = t[frame % NAVG] - t0;
00124     if (t0 > 20000ULL) LINFO("Display took %lluus", t0);
00125 
00126     // compute and show framerate over the last NAVG frames:
00127     if (frame % NAVG == 0 && frame > 0)
00128       {
00129         uint64 avg = 0ULL; for (int i = 0; i < NAVG; i ++) avg += t[i];
00130         float avg2 = 1000.0F / float(avg) * float(NAVG);
00131         printf("Framerate: %.1f fps\n", avg2);
00132       }
00133     frame ++;
00134   }
00135 
00136   // stop all our ModelComponents
00137   manager.stop();
00138 
00139   // all done!
00140   return 0;
00141 }
00142 
00143 // ######################################################################
00144 /* So things look consistent in everyone's emacs... */
00145 /* Local Variables: */
00146 /* indent-tabs-mode: nil */
00147 /* End: */
Generated on Sun May 8 08:40:15 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3