app-show-filters.C

Go to the documentation of this file.
00001 /*!@file AppNeuro/app-show-filters.C Import images from a video device and display
00002 a number of filters */
00003 
00004 // //////////////////////////////////////////////////////////////////// //
00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00006 // University of Southern California (USC) and the iLab at USC.         //
00007 // See http://iLab.usc.edu for information about this project.          //
00008 // //////////////////////////////////////////////////////////////////// //
00009 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00010 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00011 // in Visual Environments, and Applications'' by Christof Koch and      //
00012 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00013 // pending; application number 09/912,225 filed July 23, 2001; see      //
00014 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00015 // //////////////////////////////////////////////////////////////////// //
00016 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00017 //                                                                      //
00018 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00019 // redistribute it and/or modify it under the terms of the GNU General  //
00020 // Public License as published by the Free Software Foundation; either  //
00021 // version 2 of the License, or (at your option) any later version.     //
00022 //                                                                      //
00023 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00024 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00025 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00026 // PURPOSE.  See the GNU General Public License for more details.       //
00027 //                                                                      //
00028 // You should have received a copy of the GNU General Public License    //
00029 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00030 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00031 // Boston, MA 02111-1307 USA.                                           //
00032 // //////////////////////////////////////////////////////////////////// //
00033 //
00034 // Primary maintainer for this file: Dirk Walther <walther@caltech.edu>
00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppNeuro/app-show-filters.C $
00036 // $Id: app-show-filters.C 7293 2006-10-20 18:49:55Z rjpeters $
00037 //
00038 
00039 #include "Component/ModelManager.H"
00040 #include "Devices/DeviceOpts.H"
00041 #include "Devices/FrameGrabberConfigurator.H"
00042 #include "GUI/XWinManaged.H"
00043 #include "Image/ColorOps.H"
00044 #include "Image/FilterOps.H"
00045 #include "Image/Image.H"
00046 #include "Image/Image.H"
00047 #include "Image/ImageSet.H"
00048 #include "Image/MathOps.H"
00049 #include "Image/Pixels.H"
00050 #include "Image/PyramidOps.H"
00051 #include "Image/ShapeOps.H"
00052 #include "Image/Transforms.H"
00053 #include "Image/colorDefs.H"
00054 #include "Transport/FrameIstream.H"
00055 #include "Util/log.H"
00056 
00057 
00058 // ######################################################################
00059 // ##### Main Program:
00060 // ######################################################################
00061 /*! This program grabs a frame from a framegrabber and computes and
00062   displays a number of low-level features. This was done as a demo to
00063   explain the dissection of an image into features for a public
00064   outreach project.*/
00065 int main(const int argc, const char **argv)
00066 {
00067   LOG_FLAGS &= (~LOG_FULLTRACE);
00068   // a few constants for filters
00069   const int numGrabs = 2;
00070   const int filterSize = 3;
00071   const int gaussLevel = 3;
00072   const byte colThresh = 100;
00073   const byte colMin = 0;
00074   const byte colMax = 255;
00075   const byte motThresh = 10;
00076 
00077   // instantiate a model manager:
00078   ModelManager manager("Show Filters");
00079 
00080   // Instantiate our various ModelComponents:
00081   nub::soft_ref<FrameGrabberConfigurator>
00082     gbc(new FrameGrabberConfigurator(manager));
00083   manager.addSubComponent(gbc);
00084 
00085 
00086   // choose a V4Lgrabber by default, and a few custom grabbing defaults:
00087   manager.setOptionValString(&OPT_FrameGrabberType, "V4L");
00088   manager.setOptionValString(&OPT_FrameGrabberDevice,"/dev/v4l/video0");
00089   manager.setOptionValString(&OPT_FrameGrabberDims, "320x240");
00090   manager.setOptionValString(&OPT_FrameGrabberChannel, "0");
00091   manager.setOptionValString(&OPT_FrameGrabberMode,"YUV420P");
00092 
00093   // Parse command-line:
00094   if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);
00095 
00096   // do post-command-line configs:
00097   nub::soft_ref<FrameIstream> gb = gbc->getFrameGrabber();
00098   if (gb.isInvalid())
00099     LFATAL("You need to select a frame grabber type via the "
00100            "--fg-type=XX command-line option for this program "
00101            "to be useful");
00102   const Dims dims = gb->peekDims();
00103 
00104   // let's get all our ModelComponent instances started:
00105   manager.start();
00106 
00107   // create all the windows that we will need later on
00108   // and register them with a CloseButtonListener
00109   CloseButtonListener clist;
00110   XWinManaged xCap(dims, -1, -1, "Captured");                clist.add(xCap);
00111   XWinManaged xHigh(dims, -1, -1, "High Frequencies");       clist.add(xHigh);
00112   XWinManaged xLow(dims, -1, -1, "Low Frequencies");         clist.add(xLow);
00113   XWinManaged xMot(dims, -1, -1, "Motion");            clist.add(xMot);
00114   XWinManaged xRed(dims, -1, -1, "Red");                     clist.add(xRed);
00115   XWinManaged xGrn(dims, -1, -1, "Green");                   clist.add(xGrn);
00116   XWinManaged xBlu(dims, -1, -1, "Blue");                    clist.add(xBlu);
00117   XWinManaged xYel(dims, -1, -1, "Yellow");                  clist.add(xYel);
00118   XWinManaged xCol(dims, -1, -1, "Color");            clist.add(xCol);
00119 
00120   // intialize all necessary images
00121   Image<PixRGB <byte> > iCap, cLow, cCol, cRed, cGrn, cBlu, cYel;
00122   Image<byte> iLum,iHigh,iLow,lowInp,iRed,iGrn,iBlu,iYel,oLow,diff,bin,iMot;
00123   Image<float> diffX, diffY, dUp, dDown, dLeft, dRight;
00124   bool firstTime = true;
00125 
00126   // main loop
00127   while (!clist.pressedAnyCloseButton())
00128     {
00129       // capture the image
00130       for (int i = 0; i < numGrabs; ++i)
00131         iCap = gb->readRGB();
00132       xCap.drawImage(iCap);
00133 
00134       // luminance
00135       iLum = luminance(iCap);
00136 
00137       // high and low frequencies
00138       cLow = buildPyrGaussian(iCap,0,gaussLevel+1,filterSize)[gaussLevel];
00139       cLow = rescale(cLow, iCap.getDims());
00140       iLow = luminance(cLow);
00141       xLow.drawImage(iLow);
00142       iHigh = iLum - iLow;
00143       inplaceNormalize(iHigh, byte(0), byte(255));
00144       xHigh.drawImage(iHigh);
00145 
00146       // the colors
00147       getRGBY(cLow, iRed, iGrn, iBlu, iYel, colThresh);
00148       inplaceNormalize(iRed, byte(0), byte(255));
00149       inplaceNormalize(iGrn, byte(0), byte(255));
00150       inplaceNormalize(iBlu, byte(0), byte(255));
00151       inplaceNormalize(iYel, byte(0), byte(255));
00152       cRed = colorStain(iRed, colMin, colMax, COL_RED);
00153       xRed.drawImage(cRed);
00154       cGrn = colorStain(iGrn, colMin, colMax, COL_GREEN);
00155       xGrn.drawImage(cGrn);
00156       cBlu = colorStain(iBlu, colMin, colMax, COL_BLUE);
00157       xBlu.drawImage(cBlu);
00158       cYel = colorStain(iYel, colMin, colMax, COL_YELLOW);
00159       xYel.drawImage(cYel);
00160 
00161       cCol = takeMax(takeMax(cRed,cGrn),takeMax(cBlu,cYel));
00162       xCol.drawImage(cCol);
00163 
00164       // motion
00165       if(!firstTime)
00166         {
00167           diff = absDiff(iLow, oLow);
00168           bin = makeBinary(diff, motThresh,0,1);
00169           iMot = (Image<byte>)(bin * iLum);
00170           xMot.drawImage(iMot);
00171         }
00172 
00173       firstTime = false;
00174       oLow = iLow;
00175 
00176       // end of the main loop
00177     }
00178   manager.stop();
00179 }
00180 
00181 
00182 
00183 // ######################################################################
00184 /* So things look consistent in everyone's emacs... */
00185 /* Local Variables: */
00186 /* indent-tabs-mode: nil */
00187 /* End: */
Generated on Sun May 8 08:40:08 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3