00001 /*! @file SceneUnderstanding/test-GHough.C Test the GHough */ 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: Lior Elazary <elazary@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/FeatureMatching/test-GHough.C $ 00035 // $Id: test-GHough.C 13821 2010-08-24 00:30:37Z lior $ 00036 // 00037 00038 #include "Image/Image.H" 00039 #include "Component/ModelManager.H" 00040 #include "Raster/Raster.H" 00041 #include "GUI/DebugWin.H" 00042 #include "FeatureMatching/GHough.H" 00043 #include "Image/Rectangle.H" 00044 #include "Image/FilterOps.H" 00045 00046 #include <signal.h> 00047 #include <sys/types.h> 00048 00049 int main(const int argc, const char **argv) 00050 { 00051 00052 MYLOGVERB = LOG_INFO; 00053 ModelManager manager("Test GHough"); 00054 00055 if (manager.parseCommandLine( 00056 (const int)argc, (const char**)argv, "", 0, 0) == false) 00057 return 1; 00058 00059 manager.start(); 00060 00061 GHough gHough; 00062 00063 00064 Image<PixRGB<byte> > car = Raster::ReadRGB("car.pnm"); 00065 00066 std::vector<Point2D<int> > carTempl; 00067 carTempl.push_back(Point2D<int>(151,105)); 00068 carTempl.push_back(Point2D<int>(222,100)); 00069 carTempl.push_back(Point2D<int>(240,112)); 00070 carTempl.push_back(Point2D<int>(273,113)); 00071 carTempl.push_back(Point2D<int>(279,133)); 00072 carTempl.push_back(Point2D<int>(270,135)); 00073 carTempl.push_back(Point2D<int>(265,122)); 00074 carTempl.push_back(Point2D<int>(247,123)); 00075 carTempl.push_back(Point2D<int>(241,137)); 00076 carTempl.push_back(Point2D<int>(189,140)); 00077 carTempl.push_back(Point2D<int>(182,129)); 00078 carTempl.push_back(Point2D<int>(163,130)); 00079 carTempl.push_back(Point2D<int>(157,143)); 00080 carTempl.push_back(Point2D<int>(141,144)); 00081 carTempl.push_back(Point2D<int>(143,123)); 00082 carTempl.push_back(Point2D<int>(151,106)); 00083 00084 00085 //Center the template 00086 Point2D<int> center(0,0); 00087 for(uint i=0; i<carTempl.size(); i++) 00088 center += carTempl[i]; 00089 center /= carTempl.size(); 00090 00091 for(uint i=0; i<carTempl.size(); i++) 00092 carTempl[i] -= center; 00093 00094 00095 drawOutlinedPolygon(car, carTempl, PixRGB<byte>(0,255,0), 00096 Point2D<int>(207,124), 2*M_PI/180, 1); 00097 SHOWIMG(car); 00098 00099 00100 gHough.addModel(1, carTempl); 00101 00102 Image<float> inCar = luminance(car); 00103 SHOWIMG(inCar); 00104 00105 gHough.getVotes(inCar); 00106 00107 00108 //Image<float> modelImage(320,240,ZEROS); //The input image 00109 00110 ////Draw a shape in the image 00111 //drawSuperquadric(modelImage, 00112 // Point2D<int>(150,100), 00113 // 20, //shape width 00114 // 40, //shape height 00115 // 0.8, //shape param 00116 // 255.0F, //color 00117 // 0, //angle 00118 // 0, //sheer x 00119 // 0, //sheer y 00120 // -M_PI, //start 00121 // M_PI, //end 00122 // 20); 00123 00124 ////Learn the shape 00125 //SHOWIMG(modelImage); 00126 //gHough.addModel(1, modelImage); 00127 00128 00129 ////FInd the shape 00130 //Image<float> inImage(320,240,ZEROS); //The input image 00131 00132 ////Draw a shape in the image 00133 //drawSuperquadric(inImage, 00134 // Point2D<int>(100,70), 00135 // 10, //shape width 00136 // 20, //shape height 00137 // 0.8, //shape param 00138 // 255.0F, //color 00139 // 45*M_PI/180, //angle 00140 // 0, //sheer x 00141 // 0, //sheer y 00142 // -M_PI, //start 00143 // M_PI, //end 00144 // 20); 00145 00146 ////drawSuperquadric(inImage, 00147 //// Point2D<int>(250,70), 00148 //// 10, //shape width 00149 //// 20, //shape height 00150 //// 2.8, //shape param 00151 //// 255.0F, //color 00152 //// 0, //angle 00153 //// 0, //sheer x 00154 //// 0, //sheer y 00155 //// -M_PI, //start 00156 //// M_PI, //end 00157 //// 20); 00158 00159 ////Learn the shape 00160 //SHOWIMG(inImage); 00161 //gHough.getVotes(inImage); 00162 00163 ////Create a model object 00164 //Image<float> tmp(320,240, ZEROS); 00165 //Image<float> mag, ori; 00166 00167 00168 //for(uint i=0; i<10; i++) 00169 //{ 00170 // tmp.clear(); 00171 // int d = int((i/10.0F)*50); 00172 // drawRectOR(tmp, Rectangle(Point2D<int>(128,128), Dims(d, d)), 00173 // 1.0F, d, 0); 00174 // gradientSobel(tmp, mag, ori); 00175 // ghough.addModel(i, mag, ori); 00176 //} 00177 00178 //for(uint i=0; i<10; i++) 00179 //{ 00180 // tmp.clear(); 00181 // int d = int((i/10.0F)*50); 00182 // drawDisk(tmp, Point2D<int>(128,128), d, 1.0F); 00183 // gradientSobel(tmp, mag, ori); 00184 // ghough.addModel(20+i, mag, ori); 00185 //} 00186 00187 //ghough.writeTable("test.dat"); 00188 //ghough.readTable("test.dat"); 00189 00190 00191 00192 //for(int x=50; x<200; x+=10) 00193 // for(int y=50; y<200; y+=10) 00194 // for(int rot=0; rot<1; rot+=10) 00195 // { 00196 // Image<float> img(320,240, ZEROS); 00197 // drawRectOR(img, Rectangle(Point2D<int>(x,y), Dims(15, 15)), 00198 // 1.0F, 15, rot); 00199 00200 // drawDisk(img, Point2D<int>(100,100), 30, 1.0F); 00201 00202 // //Draw some random lines 00203 // for(uint i=0; i<50; i++) 00204 // { 00205 // Point2D<int> p1(randomUpToIncluding(319), randomUpToIncluding(239)); 00206 // Point2D<int> p2(randomUpToIncluding(319), randomUpToIncluding(239)); 00207 // drawLine(img, p1, p2, 1.0F); 00208 // } 00209 00210 // SHOWIMG(img); 00211 00212 // Image<float> mag, ori; 00213 // gradientSobel(img, mag, ori); 00214 00215 // std::vector<GHough::Acc> acc = ghough.getVotes(mag, ori); 00216 // Image<float> accImg(mag.getDims(), ZEROS); 00217 // for(uint i=0; i<acc.size(); i++) 00218 // if (accImg.coordsOk(acc[i].pos)) 00219 // accImg.setVal(acc[i].pos, accImg.getVal(acc[i].pos) + acc[i].votes); 00220 00221 // SHOWIMG(accImg); 00222 00223 // inplaceNormalize(img, 0.0F, 255.0F); 00224 00225 // Image<PixRGB<byte> > results = img; 00226 // for(uint i=0; i<10; i++) 00227 // { //Show the top 10 00228 // drawCircle(results, acc[i].pos, 3, PixRGB<byte>(0,255,0)); 00229 // LINFO("%i: Max is %i",i, acc[i].id); 00230 // } 00231 // SHOWIMG(results); 00232 00233 // } 00234 00235 00236 manager.stop(); 00237 00238 return 0; 00239 } 00240