test-colorSegment.C

Go to the documentation of this file.
00001 /*!@file VFAT/test-colorSegment.C Test IEEE1394 frame grabbing and X display */
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:  T. Nathan Mundhenk <mundhenk@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/VFAT/test-colorSegment.C $
00035 // $Id: test-colorSegment.C 6988 2006-08-11 17:15:38Z rjpeters $
00036 //
00037 
00038 
00039 #include "Component/ModelManager.H"
00040 #include "Devices/CameraControl.H"
00041 #include "Devices/FrameGrabberConfigurator.H"
00042 #include "GUI/XWindow.H"
00043 #include "Transport/FrameIstream.H"
00044 #include "VFAT/segmentImageMerge.H"
00045 #include "rutz/shared_ptr.h"
00046 
00047 #include <cstdio>
00048 #include <cstdlib>
00049 
00050 // number of frames over which framerate info is averaged:
00051 #define NAVG 20
00052 
00053 int main(const int argc, const char **argv)
00054 {
00055 
00056   // instantiate a model manager:
00057   ModelManager manager("Frame Grabber Tester");
00058 
00059   // Instantiate our various ModelComponents:
00060   nub::soft_ref<FrameGrabberConfigurator>
00061     gbc(new FrameGrabberConfigurator(manager));
00062   manager.addSubComponent(gbc);
00063 
00064   nub::soft_ref<CameraControl>
00065     camera(new CameraControl(manager, "Camera Controller", "CameraControl",
00066                              0, true, 0, 1, 1));
00067   manager.addSubComponent(camera);
00068 
00069   // Parse command-line:
00070   if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);
00071 
00072   // do post-command-line configs:
00073   nub::soft_ref<FrameIstream> gb = gbc->getFrameGrabber();
00074   if (gb.isInvalid())
00075     LFATAL("You need to select a frame grabber type via the "
00076            "--fg-type=XX command-line option for this program "
00077            "to be useful");
00078   int width = gb->getWidth(), height = gb->getHeight();
00079   float delay = 0;
00080 
00081   // let's get all our ModelComponent instances started:
00082   manager.start();
00083   XWindow wini(Dims(width, height), 0, 0, "test-input window");
00084   XWindow wino1(Dims(width/4, height/4), 0, 0, "test-output window 1");
00085   XWindow wino2(Dims(width/4, height/4), 0, 0, "test-output window 2");
00086   XWindow winAux1(Dims(100, 450), 0, 0, "HSV levels 1");
00087   XWindow winAux2(Dims(100, 450), 0, 0, "HSV levels 2");
00088   Timer tim; Image< PixRGB<byte> > ima; Image< PixRGB<float> > fima;
00089   Image< PixRGB<byte> > display;
00090   Timer camPause;       // to pause the move command
00091   camPause.reset();
00092   uint64 t[NAVG]; int frame = 0;
00093   segmentImageMerge segmenter(2);
00094   // set up tracking parameters
00095   //segmenter.setTrackColor(10,10,0.15,0.20,150,150,0,true,15);
00096   segmenter.setTrackColor(13,7,0.17,0.3,156,30,0,true,15);
00097   //segmenter.setTrackColor(10,10,0.15,0.20,150,150,1,false,15);
00098   segmenter.setTrackColor(270,10,0.18,0.25,60,60,1,true,15);
00099   segmenter.setAdaptBound(20,5,.30,.15,170,100,0);
00100   //segmenter.setAdaptBound(15,5,.30,.25,140,100,0);
00101   segmenter.setAdaptBound(285,265,.25,.15,80,40,1);
00102   segmenter.setFrame(0,0,width/4,height/4,width/4,height/4,0);
00103   segmenter.setFrame(0,0,width/4,height/4,width/4,height/4,1);
00104   segmenter.setCircleColor(0,255,0,0);
00105   segmenter.setCircleColor(0,0,255,1);
00106   segmenter.setBoxColor(255,255,0,0);
00107   segmenter.setBoxColor(255,0,255,1);
00108 
00109   segmenter.setAdapt(3,true,3,true,3,true,0);
00110   segmenter.setAdapt(3,true,3,true,3,true,1);
00111 
00112   while(1) {
00113     tim.reset();
00114     ima = gb->readRGB();
00115     uint64 t0 = tim.get();  // to measure display time
00116 
00117     Image<PixRGB<byte> > Aux1;
00118     Image<PixRGB<byte> > Aux2;
00119     Aux1.resize(100,450,true);
00120     Aux2.resize(100,450,true);
00121 
00122     Image<byte> outputI1;
00123     Image<byte> outputI2;
00124 
00125     display = ima;
00126     segmenter.trackImage(ima,&display,0,&Aux1);
00127     segmenter.trackImage(ima,&display,1,&Aux2);
00128     segmenter.mergeImages(&display);
00129 
00130     if(camPause.get() > delay)
00131     {
00132       int modi,modj;
00133       segmenter.getImageTrackXY(&modi,&modj,0);
00134       //segmenter.getImageTrackXYMerge(&modi,&modj);
00135       modi = modi*8;
00136       modj = 480-modj*8;
00137       if(modi > 0 && modi < 640 && modj > 0 && modj < 480)
00138       {
00139         if(segmenter.returnLOT(0) == false)
00140         {
00141           camPause.reset();
00142           delay = camera->moveCamXYFrame(modi,modj);
00143         }
00144       }
00145     }
00146 
00147     Image<byte> temp1 = segmenter.returnCandidateImage(0);
00148     Image<byte> temp2 = segmenter.returnCandidateImage(1);
00149     wini.drawImage(display);
00150     //wino1.drawImage(outputI1);
00151     wino1.drawImage(temp1);
00152     wino2.drawImage(temp2);
00153     winAux1.drawImage(Aux1);
00154     winAux2.drawImage(Aux2);
00155     t[frame % NAVG] = tim.get();
00156     t0 = t[frame % NAVG] - t0;
00157     if (t0 > 28) LINFO("Display took %llums", t0);
00158 
00159     // compute and show framerate over the last NAVG frames:
00160     if (frame % NAVG == 0 && frame > 0)
00161     {
00162       uint64 avg = 0; for (int i = 0; i < NAVG; i ++) avg += t[i];
00163       float avg2 = 1000.0 / (float)avg * NAVG;
00164       printf("Framerate: %.1f fps\n", avg2);
00165     }
00166     frame ++;
00167   }
00168 
00169   manager.stop();
00170   return 0;
00171 }
00172 
00173 // ######################################################################
00174 /* So things look consistent in everyone's emacs... */
00175 /* Local Variables: */
00176 /* indent-tabs-mode: nil */
00177 /* End: */
Generated on Sun May 8 08:42:36 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3