00001 /*! @file SceneUnderstanding/test-GeomHash */ 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-GeomHash.C $ 00035 // $Id: test-GeomHash.C 12962 2010-03-06 02:13:53Z irock $ 00036 // 00037 00038 #include "FeatureMatching/GeometricHashing.H" 00039 #include "Image/Point2D.H" 00040 #include "GUI/DebugWin.H" 00041 #include "Util/MathFunctions.H" 00042 00043 #include <signal.h> 00044 #include <sys/types.h> 00045 00046 void drawInput(std::vector<Point2D<float> >& input, 00047 std::vector<Point2D<float> >& model) 00048 { 00049 float binWidth = 20; 00050 Image<PixRGB<byte> > img(int(32*binWidth), int(32*binWidth), ZEROS); 00051 drawGrid(img, (int)binWidth, (int)binWidth, 1, 1, PixRGB<byte>(0,0,255)); 00052 drawLine(img, Point2D<int>(0, img.getHeight()/2), 00053 Point2D<int>(img.getWidth(), img.getHeight()/2), 00054 PixRGB<byte>(0,0,255),2); 00055 drawLine(img, Point2D<int>(img.getWidth()/2, 0), 00056 Point2D<int>(img.getWidth()/2, img.getHeight()), 00057 PixRGB<byte>(0,0,255),2); 00058 00059 //draw the Input 00060 float scale = 20; 00061 for(uint i=0; i<input.size(); i++) 00062 { 00063 int x = (img.getWidth()/2) + (int)(scale*input[i].i); 00064 int y = (img.getHeight()/2) - (int)(scale*input[i].j); 00065 drawCircle(img, Point2D<int>(x,y), 3, PixRGB<byte>(255,0,0)); 00066 } 00067 00068 //draw the Model 00069 for(uint i=0; i<model.size(); i++) 00070 { 00071 int x = (img.getWidth()/2) + (int)(scale*model[i].i); 00072 int y = (img.getHeight()/2) - (int)(scale*model[i].j); 00073 drawCircle(img, Point2D<int>(x,y), 5, PixRGB<byte>(0,255,0)); 00074 } 00075 00076 SHOWIMG(img); 00077 } 00078 int main(const int argc, const char **argv) 00079 { 00080 00081 GeometricHashing gHash; 00082 00083 GeometricHashing::Model model; 00084 00085 //model.v.push_back(Point2D<float>(5+2,2+3.464102)); 00086 //model.v.push_back(Point2D<float>(5+7.556922, 2+3.488973)); 00087 //model.v.push_back(Point2D<float>(5+-1.110512, 2+6.876537)); 00088 //model.v.push_back(Point2D<float>(5+-2.000000, 2+-3.464102)); 00089 //model.v.push_back(Point2D<float>(5+6.022947, 2+-1.167949)); 00090 00091 //std::vector<Point2D<float> > input; 00092 //input.push_back(Point2D<float>(1, 7)); 00093 //input.push_back(Point2D<float>(9, 6)); 00094 //input.push_back(Point2D<float>(1+2,1+3.464102)); 00095 //input.push_back(Point2D<float>(1+7.556922, 1+3.488973)); 00096 //input.push_back(Point2D<float>(1+-1.110512, 1+6.876537)); 00097 //input.push_back(Point2D<float>(1+-2.000000, 1+-3.464102)); 00098 //input.push_back(Point2D<float>(1+6.022947, 1+-1.167949)); 00099 //input.push_back(Point2D<float>(1+1.022947, 1+-3.167949)); 00100 //input.push_back(Point2D<float>(1+2.022947, 1+-2.167949)); 00101 //input.push_back(Point2D<float>(1+3.022947, 1+-7.167949)); 00102 //input.push_back(Point2D<float>(-1.022947, -3.167949)); 00103 //input.push_back(Point2D<float>(-2.022947, -2.167949)); 00104 // 00105 //gHash.addModel(model); 00106 //Image<PixRGB<byte> > img = gHash.getHashTableImage(); 00107 //LINFO("Show Hash table\n"); 00108 ////SHOWIMG(img); 00109 00110 //LINFO("Show Input"); 00111 //std::vector<Point2D<float> > modelF; 00112 ////drawInput(input, modelF); 00113 00114 ////Find the model in the input 00115 //std::vector<GeometricHashing::Acc> acc = gHash.getVotes(input); 00116 //if (acc.size() > 0) 00117 //{ 00118 // //Find the max 00119 // GeometricHashing::Acc maxAcc = acc[0]; 00120 // for(uint i=1; i<acc.size(); i++) 00121 // if (acc[i].votes > maxAcc.votes) 00122 // maxAcc = acc[i]; 00123 00124 // LINFO("Found model at: %i %i %i %i (%i %i)\n", 00125 // maxAcc.P1, maxAcc.P2, maxAcc.modelId, maxAcc.votes, 00126 // maxAcc.inputP1, maxAcc.inputP2); 00127 00128 // //Change the basis of the model to find the input 00129 // Point2D<float> p1 = input[maxAcc.inputP1]; //Get the input basis 00130 // Point2D<float> p2 = input[maxAcc.inputP2]; //Get the input basis 00131 00132 // //Find the transformation 00133 // float modelScale = sqrt( squareOf(p2.i - p1.i) + squareOf(p2.j - p1.j) ); 00134 // float ang = atan((p2.j - p1.j)/(p2.i - p1.i)); 00135 // Point2D<float> center(p1.i+(p2.i - p1.i)/2, p1.j+(p2.j - p1.j)/2); 00136 // 00137 // //Change the basis of the model to the basis that we found 00138 // modelF = gHash.changeBasis(model.v, maxAcc.P1, maxAcc.P2); 00139 00140 // //Change the basis of the mode to the input 00141 // for(uint i=0; i<modelF.size(); i++) 00142 // { 00143 // float x = modelScale*(modelF[i].i); 00144 // float y = modelScale*(modelF[i].j); 00145 // modelF[i] = Point2D<float>((x * cos(ang) - y * sin(ang)), 00146 // (y * cos(ang) + x * sin(ang))); 00147 // } 00148 // for(uint i=0; i<modelF.size(); i++) 00149 // modelF[i] += center; 00150 00151 // drawInput(input, modelF); 00152 //} 00153 00154 00155 return 0; 00156 } 00157