00001 /*! @file SceneUnderstanding/test-FDCM.C Test the FDCM */ 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: $ 00035 // $Id: $ 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 "FeatureMatching/OriChamferMatching.H" 00044 #include "Image/Rectangle.H" 00045 #include "Image/FilterOps.H" 00046 00047 #include <signal.h> 00048 #include <sys/types.h> 00049 00050 int main(const int argc, const char **argv) 00051 { 00052 00053 MYLOGVERB = LOG_INFO; 00054 ModelManager manager("Test FDCM"); 00055 00056 if (manager.parseCommandLine( 00057 (const int)argc, (const char**)argv, "", 0, 0) == false) 00058 return 1; 00059 00060 manager.start(); 00061 00062 //LMLineMatcher lineMatcher; 00063 //lineMatcher.Configure("para_line_matcher.txt"); 00064 00065 00066 //Generate a random image 00067 for(float ori=360; ori>10; ori-=10) 00068 { 00069 Image<PixRGB<byte> > inputImg(320,240,ZEROS); 00070 Point2D<int> pos(100,100); 00071 float len=50; 00072 float x1 = cos(ori*M_PI/180)*len/2; 00073 float y1 = sin(ori*M_PI/180)*len/2; 00074 00075 Point2D<float> p1(pos.i-x1, pos.j+y1); 00076 Point2D<float> p2(pos.i+x1, pos.j-y1); 00077 00078 drawLine(inputImg, (Point2D<int>)p1, (Point2D<int>)p2, PixRGB<byte>(255,0,0)); 00079 00080 00081 //Build the FDCM 00082 std::vector<Line> lines; 00083 lines.push_back(Line(p1,p2)); 00084 OriChamferMatching matcher(lines, 00085 60, //Num Orientations 00086 2.5, //Direction cost 00087 inputImg.getDims()); 00088 00089 00090 //lineMatcher.computeIDT3(inputImg.getWidth(), inputImg.getHeight(), 00091 // lines.size(), &lines[0]); 00092 00093 //Build the template model and match 00094 00095 Image<float> costImg(inputImg.getDims(), NO_INIT); 00096 costImg.clear(1e10); 00097 for(int y=0; y<inputImg.getHeight(); y++) 00098 { 00099 for(int x=0; x<inputImg.getWidth(); x++) 00100 { 00101 for(int ori=0; ori < 360; ori++) 00102 { 00103 Point2D<int> pos(x,y); 00104 float len=50; 00105 float x1 = cos((ori)*M_PI/180)*len/2; 00106 float y1 = sin((ori)*M_PI/180)*len/2; 00107 00108 Point2D<float> p1(pos.i-x1, pos.j+y1); 00109 Point2D<float> p2(pos.i+x1, pos.j-y1); 00110 00111 Polygon model; 00112 model.addLine(Line(p1,p2)); 00113 model.quantize(60); 00114 00115 for(uint i=0; i<model.getNumLines(); i++) 00116 { 00117 Line l = model.getLine(i); 00118 00119 float sum = matcher.getCost(l.getDirectionIdx(), Point2D<int>(l.getP1()), Point2D<int>(l.getP2())); 00120 //float sum2 = matcher.getCostFast(l.getDirectionIdx(), Point2D<int>(l.getP1()), Point2D<int>(l.getP2())); 00121 //LINFO("Line %i cost %f %f",i, sum, costImg.getVal(x,y)); 00122 if (sum < costImg.getVal(x,y)) 00123 costImg.setVal(x,y,sum); 00124 } 00125 } 00126 } 00127 LINFO("Y %i", y); 00128 } 00129 SHOWIMG(costImg); 00130 00131 00132 //SHOWIMG(inputImg); 00133 } 00134 00135 00136 00137 00138 manager.stop(); 00139 00140 return 0; 00141 } 00142