ComplexObject.C

Go to the documentation of this file.
00001 /*!@file BeoSub/ComplexObject.C Simple shape models */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // 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: Kevin Jones <kevinjon@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/BeoSub/ComplexObject.C $
00035 // $Id: ComplexObject.C 10746 2009-02-03 07:09:00Z itti $
00036 //
00037 
00038 #include "ComplexObject.H"
00039 #include "Image/DrawOps.H"
00040 #include "Image/ColorOps.H"
00041 #include "GUI/XWindow.H"
00042 
00043 #include <cmath>
00044 #include <fstream>
00045 
00046 // ######################################################################
00047 ComplexObject::ComplexObject(char* name, char* vodbName)
00048 {
00049   itsName = name;
00050   itsVODBName = vodbName;
00051   MYLOGVERB=LOG_CRIT;
00052 
00053   if (itsVODB.loadFrom(vodbName) == false)
00054     LFATAL("Cannot operate without a valid database.");
00055 
00056 
00057 
00058   std::string objectfilestr = vodbName;
00059 
00060 
00061   std::string filepathstr = objectfilestr.substr(0, objectfilestr.find_last_of('/')+1);
00062 
00063 
00064 }
00065 
00066 // ######################################################################
00067 
00068 ComplexObject::ComplexObject(char* objFile)
00069 {
00070 
00071 
00072   std::ifstream is(objFile);
00073   std::string name ="";
00074   std::string vodbName ="";
00075   std::string objFileStr = objFile;
00076 
00077   if (is.is_open() == false) {
00078     LERROR("Cannot open object '%s' ", objFile);
00079     return;
00080   }
00081 
00082 
00083   std::string filepath = objFileStr.substr(0, objFileStr.find_last_of('/')+1);
00084 
00085   getline(is, name);
00086   getline(is, vodbName);
00087   vodbName = filepath + vodbName;
00088 
00089 
00090  itsName = name;
00091 
00092   printf("VODB: %s \t Object Name: %s \n", vodbName.c_str(), itsName.c_str());
00093   itsVODBName = (char*)vodbName.c_str();
00094   MYLOGVERB=LOG_CRIT;
00095 
00096   if (itsVODB.loadFrom(vodbName) == false)
00097     LFATAL("Cannot operate without a valid database.");
00098 
00099 
00100 
00101   std::string objectfilestr = vodbName;
00102 
00103 
00104   std::string filepathstr = objectfilestr.substr(0, objectfilestr.find_last_of('/')+1);
00105 
00106 }
00107 
00108 
00109 // ######################################################################
00110 ComplexObject::~ComplexObject()
00111 {
00112 }
00113 
00114 
00115 
00116 // ######################################################################
00117 int ComplexObject::matchKeypoints(bool showAll, Image< PixRGB<byte> > inputImg, VisualObjectMatchAlgo voma, std::vector < rutz::shared_ptr<VisualObjectMatch> >& matches, Image< PixRGB<byte> >& kpImg, Image< PixRGB<byte> >& fusedImg)
00118 {
00119 
00120 
00121 
00122   rutz::shared_ptr<VisualObject>
00123     vo(new VisualObject("mypic", "mypicfilename", inputImg,
00124                         Point2D<int>(-1,-1), std::vector<float>(),
00125                         std::vector< rutz::shared_ptr<Keypoint> >(), true));
00126   return matchKeypoints(showAll, vo, voma, matches, kpImg, fusedImg);
00127 
00128 }
00129 
00130 
00131 // ######################################################################
00132 int ComplexObject::matchKeypoints(bool showAll, rutz::shared_ptr<VisualObject> vo, VisualObjectMatchAlgo voma, std::vector < rutz::shared_ptr<VisualObjectMatch> >& matches, Image< PixRGB<byte> >& kpImg, Image< PixRGB<byte> >& fusedImg)
00133 {
00134 
00135 
00136   // create visual object and extract keypoints:
00137   //  rutz::shared_ptr<VisualObject> vo(new VisualObject("mypic", "mypicfilename", inputImg));
00138 
00139 
00140   // get the matching objects:
00141   const uint nmatches = itsVODB.getObjectMatches(vo, matches, voma, 1);
00142 
00143 
00144   // prepare the fused image:
00145   Image< PixRGB<byte> > mimg;
00146   std::vector<Point2D<int> > tl, tr, br, bl;
00147 
00148 
00149 
00150  // if no match, forget it:
00151   if (nmatches == 0U)
00152     {
00153           printf("### No matching object found.\n");
00154     }
00155   else
00156     {
00157 
00158       // let the user know about the matches:
00159       //NOTE: while this doesn't loop through all found macthes now, it WILL still find all macthes, even if the user doesn't want to show them all. This is slow, and should be FIXed
00160       if(showAll) {
00161         for (uint i = 0; i < nmatches; i ++)
00162           {
00163             rutz::shared_ptr<VisualObjectMatch> vom = matches[i];
00164             rutz::shared_ptr<VisualObject> obj = vom->getVoTest();
00165 
00166             printf("### %s Object match with '%s' score=%f\n",
00167                    itsName.c_str(), obj->getName().c_str(), vom->getScore());
00168 
00169             // add to our fused image if desired:
00170 
00171 
00172 
00173             //we should probably test to see if the user passed a fusedImg in by reference before fusing the images together here (it'd save some time)
00174             mimg = vom->getTransfTestImage(mimg);
00175 
00176             // also keep track of the corners of the test image, for
00177             // later drawing:
00178             Point2D<int> ptl, ptr, pbr, pbl;
00179             vom->getTransfTestOutline(ptl, ptr, pbr, pbl);
00180             tl.push_back(ptl); tr.push_back(ptr);
00181             br.push_back(pbr); bl.push_back(pbl);
00182 
00183           }
00184       }
00185       else {
00186 
00187         rutz::shared_ptr<VisualObjectMatch> vom = matches[0];
00188         if (vom->checkSIFTaffine() == false)//if affine is too wierd
00189           return 0;
00190 
00191         rutz::shared_ptr<VisualObject> obj = vom->getVoTest();
00192         kpImg = vom->getMatchImage(1.0F);//NOTE: right now, only works if One match is to be shown!
00193         printf("### %s Object match with '%s' score=%f\n",
00194                itsName.c_str(), obj->getName().c_str(), vom->getScore());
00195       }
00196 
00197        // do a final mix between given image and matches:
00198       /*
00199         mimg = Image<PixRGB<byte> >(mimg * 0.5F + inputImg * 0.5F);
00200 
00201         // finally draw all the object outlines:
00202         PixRGB<byte> col(255, 255, 0);
00203         for (uint i = 0; i < tl.size(); i ++)
00204           {
00205             drawLine(mimg, tl[i], tr[i], col, 1);
00206             drawLine(mimg, tr[i], br[i], col, 1);
00207             drawLine(mimg, br[i], bl[i], col, 1);
00208             drawLine(mimg, bl[i], tl[i], col, 1);
00209           }
00210 
00211         fusedImg = mimg;
00212       */
00213     }
00214 
00215 
00216   return nmatches;
00217 }
00218 
00219 
00220 // ######################################################################
00221 /* So things look consistent in everyone's emacs... */
00222 /* Local Variables: */
00223 /* indent-tabs-mode: nil */
00224 /* End: */
Generated on Sun May 8 08:04:33 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3