00001 /*!@file VFAT/test-colorSegment2.C grab frame and track color */ 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: T. Nathan Mundhenk <mundhenk@usc.edu> 00033 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/VFAT/test-colorSegment2.C $ 00034 // $Id: test-colorSegment2.C 6988 2006-08-11 17:15:38Z rjpeters $ 00035 // 00036 00037 00038 #include "Component/ModelManager.H" 00039 #include "Devices/CameraControl.H" 00040 #include "Devices/FrameGrabberConfigurator.H" 00041 #include "GUI/XWindow.H" 00042 #include "Transport/FrameIstream.H" 00043 #include "VFAT/segmentImageMerge2.H" 00044 #include "rutz/shared_ptr.h" 00045 00046 #include <cstdio> 00047 #include <cstdlib> 00048 00049 // number of frames over which framerate info is averaged: 00050 #define NAVG 20 00051 00052 int main(const int argc, const char **argv) 00053 { 00054 00055 // instantiate a model manager: 00056 ModelManager manager("Frame Grabber Tester"); 00057 00058 // Instantiate our various ModelComponents: 00059 nub::soft_ref<FrameGrabberConfigurator> 00060 gbc(new FrameGrabberConfigurator(manager)); 00061 manager.addSubComponent(gbc); 00062 00063 nub::soft_ref<CameraControl> 00064 camera(new CameraControl(manager, "Camera Controller", "CameraControl", 00065 0, true, 0, 1, 1)); 00066 manager.addSubComponent(camera); 00067 00068 // Parse command-line: 00069 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1); 00070 00071 // do post-command-line configs: 00072 nub::soft_ref<FrameIstream> gb = gbc->getFrameGrabber(); 00073 if (gb.isInvalid()) 00074 LFATAL("You need to select a frame grabber type via the " 00075 "--fg-type=XX command-line option for this program " 00076 "to be useful"); 00077 int width = gb->getWidth(), height = gb->getHeight(); 00078 float delay = 0; 00079 00080 // let's get all our ModelComponent instances started: 00081 manager.start(); 00082 XWindow wini(Dims(width, height), 0, 0, "test-input window"); 00083 XWindow wino1(Dims(width/4, height/4), 0, 0, "test-output window 1"); 00084 XWindow wino2(Dims(width/4, height/4), 0, 0, "test-output window 2"); 00085 XWindow winAux1(Dims(100, 450), 0, 0, "HSV levels 1"); 00086 XWindow winAux2(Dims(100, 450), 0, 0, "HSV levels 2"); 00087 Timer tim; Image< PixRGB<byte> > ima; Image< PixRGB<float> > fima; 00088 Image< PixRGB<byte> > display; 00089 Timer camPause; // to pause the move command 00090 camPause.reset(); 00091 uint64 t[NAVG]; int frame = 0; 00092 00093 /* create 2 trackers that are bound togther (e.g. 2 trackers in the same 00094 camera input image 00095 */ 00096 00097 segmentImageMerge2 segmenter(2); 00098 00099 // set up tracking parameters 00100 //segmenter.setTrackColor(10,10,0.15,0.20,150,150,0,true,15); 00101 //segmenter.setTrackColor(13,7,0.17,0.3,156,30,0,true,15); 00102 00103 /* What are the mean value and std deviation for the color values 00104 you wish to track 00105 */ 00106 00107 //segmenter.SIMsetTrackColor(13,20,0.17,0.3,156,30,0,true,15); 00108 segmenter.SIMsetTrackColor(32,5,0.25,0.15,156,30,0,true,15); 00109 //segmenter.setTrackColor(10,10,0.15,0.20,150,150,1,false,15); 00110 segmenter.SIMsetTrackColor(32,5,0.25,0.15,156,30,1,true,15); 00111 00112 //segmenter.SIMsetTrackColor(270,10,0.18,0.25,60,60,1,true,15); 00113 00114 /* What are the hard limits for the color bounderies of the object 00115 you are tracking. This keeps the color adaptation within bounds 00116 */ 00117 00118 //segmenter.SIMsetAdaptBound(50,0,.6,.10,170,50,0); 00119 segmenter.SIMsetAdaptBound(40,23,.4,.10,180,120,0); 00120 //segmenter.setAdaptBound(15,5,.30,.25,140,100,0); 00121 segmenter.SIMsetAdaptBound(40,23,.4,.10,180,120,1); 00122 //segmenter.SIMsetAdaptBound(285,265,.25,.15,80,40,1); 00123 00124 /* This limits the area of consideration to an area smaller than 00125 the image size. That is, it creates a boundery in the image 00126 outside of which it will not consider pixes (i.e. a frame) 00127 */ 00128 00129 segmenter.SIMsetFrame(0,0,width/4,height/4,width/4,height/4,0); 00130 segmenter.SIMsetFrame(0,0,width/4,height/4,width/4,height/4,1); 00131 00132 /* Set display colors for output of tracking. Strictly asthetic */ 00133 00134 segmenter.SIMsetCircleColor(0,255,0,0); 00135 segmenter.SIMsetCircleColor(0,0,255,1); 00136 segmenter.SIMsetBoxColor(255,255,0,0); 00137 segmenter.SIMsetBoxColor(255,0,255,1); 00138 00139 /* What kind of color adaptation do you want. Use these values 00140 unless you understand what they do 00141 */ 00142 00143 segmenter.SIMsetAdapt(2.5,true,2.5,true,2.5,true,0,true); 00144 segmenter.SIMsetAdapt(2.5,true,2.5,true,2.5,true,1,false); 00145 00146 segmenter.SIMSetCluster(width/4,height/4,2,.6,.3,.1); 00147 00148 while(1) { 00149 tim.reset(); 00150 ima = gb->readRGB(); 00151 uint64 t0 = tim.get(); // to measure display time 00152 00153 Image<PixRGB<byte> > Aux1; 00154 Image<PixRGB<byte> > Aux2; 00155 Aux1.resize(100,450,true); 00156 Aux2.resize(100,450,true); 00157 00158 Image<byte> outputI1; 00159 Image<byte> outputI2; 00160 00161 /* Take in the image and color segment it */ 00162 00163 display = ima; 00164 segmenter.SIMtrackImage(ima,&display,0,&Aux1); 00165 segmenter.SIMtrackImage(ima,&display,1,&Aux2); 00166 00167 /* post processes segmentation for blob properties */ 00168 00169 segmenter.SIMmergeImages(&display); 00170 00171 /* if camera is not moving, then move the camera */ 00172 00173 if(camPause.get() > delay) 00174 { 00175 int modi,modj; 00176 segmenter.SIMgetImageTrackXY(&modi,&modj,0); 00177 00178 /* this is * 8 since we need to convert the image to 00179 the size 640 x 480 at the moment 00180 This will be fixed very soon! 00181 */ 00182 00183 modi = modi*8; 00184 modj = 480-modj*8; 00185 00186 /* make sure out coordinates are OK */ 00187 00188 if(modi > 0 && modi < 640 && modj > 0 && modj < 480) 00189 { 00190 if(segmenter.SIMreturnLOT(0) == false) 00191 { 00192 camPause.reset(); 00193 delay = camera->moveCamXYFrame(modi,modj); 00194 } 00195 } 00196 } 00197 00198 /* Retrieve and Draw all our output images */ 00199 00200 Image<byte> temp1 = segmenter.SIMreturnCandidateImage(0); 00201 Image<byte> temp2 = segmenter.SIMreturnCandidateImage(1); 00202 wini.drawImage(display); 00203 //wino1.drawImage(outputI1); 00204 wino1.drawImage(temp1); 00205 wino2.drawImage(temp2); 00206 winAux1.drawImage(Aux1); 00207 winAux2.drawImage(Aux2); 00208 t[frame % NAVG] = tim.get(); 00209 t0 = t[frame % NAVG] - t0; 00210 if (t0 > 28) LINFO("Display took %llums", t0); 00211 00212 // compute and show framerate over the last NAVG frames: 00213 if (frame % NAVG == 0 && frame > 0) 00214 { 00215 uint64 avg = 0; for (int i = 0; i < NAVG; i ++) avg += t[i]; 00216 float avg2 = 1000.0 / (float)avg * NAVG; 00217 printf("Framerate: %.1f fps\n", avg2); 00218 } 00219 frame ++; 00220 } 00221 00222 manager.stop(); 00223 return 0; 00224 } 00225 00226 // ###################################################################### 00227 /* So things look consistent in everyone's emacs... */ 00228 /* Local Variables: */ 00229 /* indent-tabs-mode: nil */ 00230 /* End: */