00001 /*!@file Demo/test-Colors.C Import images from a video device and display 00002 the old and new ways to compute RG and BY color opponencies */ 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/Demo/test-Colors.C $ 00036 // $Id: test-Colors.C 7754 2007-01-20 23:50:01Z itti $ 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/DrawOps.H" 00045 #include "Image/FilterOps.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 #define DOSTAIN 00058 00059 00060 // ###################################################################### 00061 // ##### Main Program: 00062 // ###################################################################### 00063 /*! This program grabs a frame from a framegrabber and computes and 00064 displays a number of low-level features. This was done as a demo to 00065 explain the dissection of an image into features for a public 00066 outreach project.*/ 00067 int main(const int argc, const char **argv) 00068 { 00069 LOG_FLAGS &= (~LOG_FULLTRACE); 00070 // a few constants for filters 00071 const int numGrabs = 3; 00072 const byte colMin = 0; 00073 const byte colMax = 255; 00074 const float RGBYthresh = 25.0F; 00075 00076 // instantiate a model manager: 00077 ModelManager manager("Show Filters"); 00078 00079 // Instantiate our various ModelComponents: 00080 nub::soft_ref<FrameGrabberConfigurator> 00081 gbc(new FrameGrabberConfigurator(manager)); 00082 manager.addSubComponent(gbc); 00083 00084 00085 // choose a V4Lgrabber by default, and a few custom grabbing defaults: 00086 manager.setOptionValString(&OPT_FrameGrabberType, "V4L"); 00087 manager.setOptionValString(&OPT_FrameGrabberDevice,"/dev/v4l/video0"); 00088 manager.setOptionValString(&OPT_FrameGrabberDims, "320x240"); 00089 manager.setOptionValString(&OPT_FrameGrabberChannel, "0"); 00090 manager.setOptionValString(&OPT_FrameGrabberMode,"YUV420P"); 00091 00092 // Parse command-line: 00093 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1); 00094 00095 // do post-command-line configs: 00096 nub::soft_ref<FrameIstream> gb = gbc->getFrameGrabber(); 00097 if (gb.isInvalid()) 00098 LFATAL("You need to select a frame grabber type via the " 00099 "--fg-type=XX command-line option for this program " 00100 "to be useful"); 00101 const Dims dims = gb->peekDims(); 00102 00103 // let's get all our ModelComponent instances started: 00104 manager.start(); 00105 00106 // create all the windows that we will need later on 00107 // and register them with a CloseButtonListener 00108 CloseButtonListener clist; 00109 XWinManaged xCap(dims,-1,-1,"Captured"); clist.add(xCap); 00110 00111 XWinManaged xRL(dims,-1,-1,"pos(RG) - Standard, clamped"); clist.add(xRL); 00112 XWinManaged xGL(dims,-1,-1,"neg(RG) - Standard, clamped"); clist.add(xGL); 00113 XWinManaged xBL(dims,-1,-1,"pos(BY) - Standard, clamped"); clist.add(xBL); 00114 XWinManaged xYL(dims,-1,-1,"neg(BY) - Standard, clamped"); clist.add(xYL); 00115 00116 XWinManaged xRD1(dims,-1,-1,"pos(RG) - Simple"); clist.add(xRD1); 00117 XWinManaged xGD1(dims,-1,-1,"neg(RG) - Simple"); clist.add(xGD1); 00118 XWinManaged xBD1(dims,-1,-1,"pos(BY) - Simple"); clist.add(xBD1); 00119 XWinManaged xYD1(dims,-1,-1,"neg(BY) - Simple"); clist.add(xYD1); 00120 00121 #ifdef DOSTAIN 00122 XWinManaged xCL(dims,-1,-1,"Colors, Standard"); clist.add(xCL); 00123 XWinManaged xCD1(dims,-1,-1,"Colors, Simple"); clist.add(xCD1); 00124 #endif 00125 00126 // main loop 00127 while (!clist.pressedAnyCloseButton()) 00128 { 00129 // capture the image 00130 Image<PixRGB <byte> > iCap; 00131 for (int i = 0; i < numGrabs; ++i) 00132 iCap = gb->readRGB(); 00133 xCap.drawImage(iCap); 00134 00135 Image<float> rg,by,rgp,rgn,byp,byn; 00136 Image<PixRGB <byte> > cR,cG,cY,cB,cCol; 00137 Image<float> zero(iCap.getDims(),ZEROS); 00138 00139 // old "Standard" method 00140 getRGBY(iCap,rg,by,RGBYthresh); 00141 00142 rgp = rg; rgn = zero - rg; 00143 byp = by; byn = zero - by; 00144 00145 inplaceClamp(rgp, 0.0f,1.0f); 00146 inplaceClamp(rgn, 0.0f,1.0f); 00147 inplaceClamp(byp, 0.0f,1.0f); 00148 inplaceClamp(byn, 0.0f,1.0f); 00149 00150 #ifdef DOSTAIN 00151 cR = colorStain(Image<byte>(rgp*255.0f),colMin,colMax,COL_RED); 00152 cG = colorStain(Image<byte>(rgn*255.0f),colMin,colMax,COL_GREEN); 00153 cB = colorStain(Image<byte>(byp*255.0f),colMin,colMax,COL_BLUE); 00154 cY = colorStain(Image<byte>(byn*255.0f),colMin,colMax,COL_YELLOW); 00155 cCol = takeMax(takeMax(cR,cG),takeMax(cB,cY)); 00156 xRL.drawImage(cR); xGL.drawImage(cG); 00157 xBL.drawImage(cB); xYL.drawImage(cY); 00158 xCL.drawImage(cCol); 00159 #else 00160 drawImage(xRL, rgp); drawImage(xGL, rgn); 00161 drawImage(xBL, byp); drawImage(xYL, byn); 00162 #endif 00163 00164 00165 // new "Simple" method 00166 getRGBYsimple(iCap,rg,by,RGBYthresh); 00167 00168 rgp = rg; rgn = zero - rg; 00169 byp = by; byn = zero - by; 00170 00171 inplaceClamp(rgp, 0.0f,1.0f); 00172 inplaceClamp(rgn, 0.0f,1.0f); 00173 inplaceClamp(byp, 0.0f,1.0f); 00174 inplaceClamp(byn, 0.0f,1.0f); 00175 00176 #ifdef DOSTAIN 00177 cR = colorStain(Image<byte>(rgp*255.0f),colMin,colMax,COL_RED); 00178 cG = colorStain(Image<byte>(rgn*255.0f),colMin,colMax,COL_GREEN); 00179 cB = colorStain(Image<byte>(byp*255.0f),colMin,colMax,COL_BLUE); 00180 cY = colorStain(Image<byte>(byn*255.0f),colMin,colMax,COL_YELLOW); 00181 cCol = takeMax(takeMax(cR,cG),takeMax(cB,cY)); 00182 xRD1.drawImage(cR); xGD1.drawImage(cG); 00183 xBD1.drawImage(cB); xYD1.drawImage(cY); 00184 xCD1.drawImage(cCol); 00185 #else 00186 xRD1.drawImage(rgp); xGD1.drawImage(rgn); 00187 xBD1.drawImage(byp); xYD1.drawImage(byn); 00188 #endif 00189 00190 // end of the main loop 00191 } 00192 manager.stop(); 00193 } 00194 00195 00196 00197 // ###################################################################### 00198 /* So things look consistent in everyone's emacs... */ 00199 /* Local Variables: */ 00200 /* indent-tabs-mode: nil */ 00201 /* End: */