app-match-SIFT-database.C

Go to the documentation of this file.
00001 /*! @file SIFT/app-match-SIFT-database.C Match an image against a database
00002   of VisualObject */
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: Laurent Itti <itti@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/SIFT/app-match-SIFT-database.C $
00035 // $Id: app-match-SIFT-database.C 9412 2008-03-10 23:10:15Z farhan $
00036 //
00037 
00038 #include "Raster/Raster.H"
00039 #include "SIFT/Keypoint.H"
00040 #include "SIFT/VisualObject.H"
00041 #include "SIFT/VisualObjectDB.H"
00042 #include "Image/DrawOps.H"
00043 
00044 /*! Load a database, an image, and find best matches. */
00045 int main(const int argc, const char **argv)
00046 {
00047   MYLOGVERB = LOG_INFO;
00048 
00049   // check command-line args:
00050   if (argc < 3 || argc > 4)
00051     LFATAL("USAGE: app-match-SIFT-database <dbname.vdb> <image.png> "
00052            "[<fused.png>]");
00053 
00054   // load the database:
00055   VisualObjectDB vdb;
00056   if (vdb.loadFrom(argv[1]) == false)
00057     LFATAL("Cannot operate without a valid database.");
00058 
00059   // get input image:
00060   Image< PixRGB<byte> > colim = Raster::ReadRGB(argv[2]);
00061 
00062   // create visual object and extract keypoints:
00063   rutz::shared_ptr<VisualObject> vo(new VisualObject(argv[2], argv[2], colim));
00064 
00065   // get the matching objects:
00066   std::vector< rutz::shared_ptr<VisualObjectMatch> > matches;
00067   const uint nmatches = vdb.getObjectMatches(vo, matches, VOMA_KDTREEBBF);
00068 
00069   // prepare the fused image:
00070   Image< PixRGB<byte> > mimg;
00071   std::vector<Point2D<int> > tl, tr, br, bl;
00072 
00073   // if no match, forget it:
00074   if (nmatches == 0U)
00075     LINFO("### No matching object found.");
00076   else
00077     {
00078       // let the user know about the matches:
00079       for (uint i = 0; i < nmatches; i ++)
00080         {
00081           rutz::shared_ptr<VisualObjectMatch> vom = matches[i];
00082           rutz::shared_ptr<VisualObject> obj = vom->getVoTest();
00083 
00084           LINFO("### Object match with '%s' score=%f",
00085                 obj->getName().c_str(), vom->getScore());
00086 
00087           // add to our fused image if desired:
00088           if (argc > 3)
00089             {
00090               mimg = vom->getTransfTestImage(mimg);
00091 
00092               // also keep track of the corners of the test image, for
00093               // later drawing:
00094               Point2D<int> ptl, ptr, pbr, pbl;
00095               vom->getTransfTestOutline(ptl, ptr, pbr, pbl);
00096               tl.push_back(ptl); tr.push_back(ptr);
00097               br.push_back(pbr); bl.push_back(pbl);
00098             }
00099         }
00100 
00101       // do a final mix between given image and matches:
00102       if (mimg.initialized())
00103         {
00104           mimg = Image<PixRGB<byte> >(mimg * 0.5F + colim * 0.5F);
00105 
00106           // finally draw all the object outlines:
00107           PixRGB<byte> col(255, 255, 0);
00108           for (uint i = 0; i < tl.size(); i ++)
00109             {
00110               drawLine(mimg, tl[i], tr[i], col, 1);
00111               drawLine(mimg, tr[i], br[i], col, 1);
00112               drawLine(mimg, br[i], bl[i], col, 1);
00113               drawLine(mimg, bl[i], tl[i], col, 1);
00114             }
00115         }
00116     }
00117 
00118   // save result image if desired:
00119   if (argc > 3)
00120     {
00121       if (mimg.initialized() == false)
00122         mimg = Image< PixRGB<byte> >(colim * 0.5F);
00123       Raster::WriteRGB(mimg, std::string(argv[3]));
00124     }
00125 
00126   return 0;
00127 }
Generated on Sun May 8 08:06:46 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3