00001 /*! @file FeatureMatching/test-PGH.C Test the PGH */ 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-PGH.C $ 00035 // $Id: test-PGH.C 12985 2010-03-09 00:18:49Z 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/PGH.H" 00043 #include "Image/Rectangle.H" 00044 #include "Image/FilterOps.H" 00045 00046 #include <signal.h> 00047 #include <sys/types.h> 00048 00049 std::vector<PGH::Line> transform(std::vector<PGH::Line>& lines, Point2D<int> pos, 00050 float scale, float rot) 00051 { 00052 std::vector<PGH::Line> newLines = lines; 00053 00054 //Get the center of mass so we can rotte around that 00055 00056 00057 Point2D<int> com(0,0); 00058 for(uint i=0; i<newLines.size(); i++) 00059 com += newLines[i].pos; 00060 com /= newLines.size(); 00061 00062 for(uint i=0; i<lines.size(); i++) 00063 { 00064 00065 ////Rotate 00066 00067 float x = scale*(newLines[i].pos.i - com.i); 00068 float y = scale*(newLines[i].pos.j - com.j); 00069 newLines[i].pos.i = com.i + int(x * cos(rot) - y * sin(rot)); 00070 newLines[i].pos.j = com.j + int(y * cos(rot) + x * sin(rot)); 00071 00072 newLines[i].pos += pos; //Transelate 00073 00074 newLines[i].length *= scale; 00075 newLines[i].ori -= rot; 00076 } 00077 00078 00079 return newLines; 00080 00081 } 00082 00083 int main(const int argc, const char **argv) 00084 { 00085 00086 MYLOGVERB = LOG_INFO; 00087 ModelManager manager("Test SFS"); 00088 00089 if (manager.parseCommandLine( 00090 (const int)argc, (const char**)argv, "", 0, 0) == false) 00091 return 1; 00092 00093 manager.start(); 00094 00095 00096 PGH pgh; 00097 00098 //Create a model object 00099 std::vector<PGH::Line> model; 00100 //Building 00101 model.push_back(PGH::Line(Point2D<int>(100, 100), 50, 0)); 00102 model.push_back(PGH::Line(Point2D<int>(100, 50), 50, 0)); 00103 model.push_back(PGH::Line(Point2D<int>(75, 75), 50, M_PI/2)); 00104 model.push_back(PGH::Line(Point2D<int>(125, 75), 50, M_PI/2)); 00105 00106 //Roof 00107 model.push_back(PGH::Line(Point2D<int>(80, 40), 60, M_PI/3.7)); 00108 model.push_back(PGH::Line(Point2D<int>(120, 40), 60, -M_PI/3.7)); 00109 00110 //Show model 00111 Image<PixRGB<byte> > img(320, 240, ZEROS); 00112 for(uint i=0; i<model.size(); i++) 00113 { 00114 drawLine(img, model[i].pos, model[i].ori, model[i].length, PixRGB<byte>(255,0,0)); 00115 } 00116 SHOWIMG(img); 00117 00118 00119 std::vector<PGH::Line> newLines2 = transform(model,Point2D<int>(50,50), 1.0F, float(M_PI/8)); 00120 00121 pgh.addModel(newLines2, 0); 00122 00123 for(float rot = 0; rot < 2*M_PI; rot+=10*M_PI/180) 00124 { 00125 Point2D<int> pos(50,50); 00126 float scale = 1; 00127 std::vector<PGH::Line> newLines = transform(model,pos, scale, rot); 00128 00129 img = Image<PixRGB<byte> >(320, 240, ZEROS); 00130 for(uint i=0; i<model.size(); i++) 00131 { 00132 drawLine(img, newLines[i].pos, newLines[i].ori, newLines[i].length, 00133 PixRGB<byte>(255,0,0)); 00134 } 00135 00136 pgh.matchModel(newLines); 00137 00138 SHOWIMG(img); 00139 } 00140 00141 00142 00143 manager.stop(); 00144 00145 return 0; 00146 } 00147