test-logPolar.C

Go to the documentation of this file.
00001 /*!@file AppMedia/test-logPolar.C */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00005 // by the 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: Rob Peters <rjpeters at usc dot edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppMedia/test-logPolar.C $
00035 // $Id: test-logPolar.C 9412 2008-03-10 23:10:15Z farhan $
00036 //
00037 
00038 #ifndef APPMEDIA_TEST_LOGPOLAR_C_DEFINED
00039 #define APPMEDIA_TEST_LOGPOLAR_C_DEFINED
00040 
00041 #include "Component/ModelManager.H"
00042 #include "GUI/XWinManaged.H"
00043 #include "Image/DrawOps.H"
00044 #include "Image/Image.H"
00045 #include "Image/LogPolarTransform.H"
00046 #include "Image/Pixels.H"
00047 #include "Media/FrameSeries.H"
00048 #include "Raster/GenericFrame.H"
00049 #include "Raster/Raster.H"
00050 #include "Transport/FrameInfo.H"
00051 #include "Util/CpuTimer.H"
00052 #include "Util/Pause.H"
00053 #include "Util/csignals.H"
00054 
00055 // int main(int argc, const char** argv)
00056 // {
00057 //   Image<PixRGB<byte> > inp(512, 512, ZEROS);
00058 //   inp.clear(PixRGB<byte>(255, 255, 255));
00059 
00060 //   const int w = inp.getWidth();
00061 //   const int h = inp.getHeight();
00062 
00063 //   for (int j = 0; j < h; ++j)
00064 //     for (int i = 0; i < w; ++i)
00065 //       {
00066 //         if (j < h/2)
00067 //           {
00068 //             if (i < w/2)
00069 //               inp.setVal(i, j, PixRGB<byte>(255, 192, 192));
00070 //             else
00071 //               inp.setVal(i, j, PixRGB<byte>(192, 255, 192));
00072 //           }
00073 //         else
00074 //           {
00075 //             if (i < w/2)
00076 //               inp.setVal(i, j, PixRGB<byte>(192, 192, 255));
00077 //             else
00078 //               inp.setVal(i, j, PixRGB<byte>(255, 255, 192));
00079 //           }
00080 //       }
00081 
00082 // //   drawGrid(inp, 32, 32, 2, 2, PixRGB<byte>(255, 0, 0));
00083 
00084 //   for (int ori = 0; ori < 360; ori += 30)
00085 //     {
00086 //       const double rad = ori * M_PI / 180.0;
00087 //       drawLine(inp, Point2D<int>(inp.getWidth() / 2, inp.getHeight() / 2),
00088 //                rad, inp.getWidth() * 2, PixRGB<byte>(255, 0, 0), 2);
00089 //     }
00090 
00091 //   for (int rad = 63; rad < inp.getWidth() / 2; rad += 64)
00092 //     {
00093 //       drawCircle(inp, Point2D<int>(inp.getWidth() / 2, inp.getHeight() / 2),
00094 //                  rad, PixRGB<byte>(0, 0,
00095 //                                    double(255.0 * rad / (inp.getWidth() / 2))),
00096 //                  2);
00097 //     }
00098 
00099 //   CpuTimer tm;
00100 
00101 //   LogPolarTransform t(inp.getDims(), Dims(375, 200), 0.3, 0.25);
00102 
00103 //   tm.mark(); tm.report("setup"); tm.reset();
00104 
00105 //   Image<PixRGB<byte> > btxf = t.transform(inp, PixRGB<byte>(255));
00106 
00107 //   tm.mark(); tm.report("transform"); tm.reset();
00108 
00109 //   XWinManaged win(inp);
00110 
00111 //   XWinManaged win2(btxf);
00112 
00113 //   while (!win.pressedCloseButton())
00114 //     sleep(1);
00115 // }
00116 
00117 int submain(const int argc, const char **argv)
00118 {
00119   volatile int signum = 0;
00120   catchsignals(&signum);
00121 
00122   ModelManager manager("Streamer");
00123 
00124   nub::soft_ref<InputFrameSeries> ifs(new InputFrameSeries(manager));
00125   manager.addSubComponent(ifs);
00126 
00127   nub::soft_ref<OutputFrameSeries> ofs(new OutputFrameSeries(manager));
00128   manager.addSubComponent(ofs);
00129 
00130   if (manager.parseCommandLine(argc, argv, "", 0, 0) == false)
00131     return(1);
00132 
00133   manager.start();
00134 
00135   ifs->startStream();
00136 
00137   const Dims indims = ifs->peekDims();
00138 
00139   LogPolarTransform t(indims, Dims(375, 200), 0.3, 0.25);
00140 
00141   int c = 0;
00142 
00143   PauseWaiter p;
00144 
00145   while (true)
00146     {
00147       if (signum != 0)
00148         {
00149           LINFO("quitting because %s was caught", signame(signum));
00150           return -1;
00151         }
00152 
00153       if (ofs->becameVoid())
00154         {
00155           LINFO("quitting because output stream was closed or became void");
00156           return 0;
00157         }
00158 
00159       if (p.checkPause())
00160         continue;
00161 
00162       const FrameState is = ifs->updateNext();
00163       if (is == FRAME_COMPLETE)
00164         break;
00165 
00166       GenericFrame input = ifs->readFrame();
00167       if (!input.initialized())
00168         break;
00169 
00170       const FrameState os = ofs->updateNext();
00171 
00172       const Image<PixRGB<byte> > txf = logPolarTransform(t, input.asRgb(), PixRGB<byte>(255));
00173 
00174       ofs->writeFrame(input, "input",
00175                       FrameInfo("input frame", SRC_POS));
00176 
00177       ofs->writeRGB(txf, "logpolar",
00178                     FrameInfo("log-polar transform of input frame", SRC_POS));
00179 
00180       if (os == FRAME_FINAL)
00181         break;
00182 
00183       LDEBUG("frame %d", c++);
00184 
00185       if (ifs->shouldWait() || ofs->shouldWait())
00186         Raster::waitForKey();
00187     }
00188 
00189   return 0;
00190 }
00191 
00192 int main(const int argc, const char **argv)
00193 {
00194   try
00195     {
00196       return submain(argc, argv);
00197     }
00198   catch (...)
00199     {
00200       REPORT_CURRENT_EXCEPTION;
00201     }
00202 
00203   return 1;
00204 }
00205 
00206 // ######################################################################
00207 /* So things look consistent in everyone's emacs... */
00208 /* Local Variables: */
00209 /* mode: c++ */
00210 /* indent-tabs-mode: nil */
00211 /* End: */
00212 
00213 #endif // APPMEDIA_TEST_LOGPOLAR_C_DEFINED
Generated on Sun May 8 08:04:11 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3