Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

SiftTekkotsu.h

Go to the documentation of this file.
00001 #ifndef __SIFTTEKKOTSU_H
00002 #define __SIFTTEKKOTSU_H
00003 
00004 #include "Vision/SIFT/SIFTDatabase/KnowledgeBase.h"
00005 #include "Vision/SIFT/ImageHandling/SIFTImage.h"
00006 #include <vector>
00007 #include <string>
00008 
00009 class SIFTImage;
00010 class SiftMatch;
00011 
00012 namespace DualCoding {
00013   typedef unsigned char uchar;
00014   template<typename T> class Sketch;
00015 }
00016 
00017 /**
00018    Main API class
00019    All API function calls are implemented within this class
00020    Look at APIExample.cc for an example of how to use the class to perform API calls
00021 **/
00022 class SiftTekkotsu{
00023 private:
00024   KnowledgeBase kb;
00025   std::vector<SIFTImage*> imageDatabase;
00026 public:
00027   SIFTImage testSIFTImage;
00028 private:
00029   int siftImageMaxID;
00030     
00031   char** argv, **argvCopy;
00032   int    argc;
00033     
00034   // Detection of keypoints from image using SIFT++
00035 public:
00036   void detectKeypoints(ImageBuffer buffer, std::vector<keypoint*>& keys, std::vector< std::vector< std::vector<int> > >& gaussianSpace);
00037 private:
00038   void detectKeypoints(std::string PGMFileName, ImageBuffer* buffer, 
00039            std::vector<keypoint*>& keys, std::vector< std::vector< std::vector<int> > >& gaussianSpace, bool imageProvided);
00040 
00041 public:   
00042   void findInImage(ImageBuffer buffer, std::vector<SiftMatch*>& matchesFound, bool objectSpecified, int wantedObjectID);
00043   void findInImage(std::vector<keypoint*>& keys, std::vector<SiftMatch*>& matchesFound, bool objectSpecified, int wantedObjectID);
00044 private:
00045   void clearTestState();
00046     
00047   int train_addNewObject(std::vector<keypoint*>& keys);
00048   int train_removeObject(std::vector<keypoint*>& keys, int oID);
00049   int train_addToObject(int objectID, std::vector<keypoint*>& keys, object* wantedObject, SiftMatch& matchFound);
00050   int train_removefromObject(int objectID, std::vector<keypoint*>& keys, object* wantedObject, SiftMatch& matchFound);
00051   int train_addNewModel(int objectID, std::vector<keypoint*>& keys, object* wantedObject);
00052   int train_removeModel(int objectID, std::vector<keypoint*>& keys, object* wantedObject, int mID);
00053   void convertSiftMatchFromModelMatchingInfo(SiftMatch& sMatch, KnowledgeBase::modelMatchingInfo& mminfo);
00054     
00055   int convertSiftImageIDToIndex(int siftImageID);
00056     
00057 public:
00058   SiftTekkotsu();
00059   ~SiftTekkotsu();
00060     
00061   /// Training API calls
00062     
00063   // Create a new object
00064   // Returns object ID
00065   int train_addNewObject(std::string PGMFileName);             
00066   int train_addNewObject(std::string PGMFileName, unsigned int& siftImageID);
00067   int train_addNewObject(ImageBuffer buffer);
00068   int train_addNewObject(ImageBuffer buffer, unsigned int& siftImageID);
00069     
00070   int train_removeObject(std::string PGMFileName, int oID);             
00071   int train_removeObject(std::string PGMFileName, unsigned int& siftImageID, int oID);
00072   int train_removeObject(ImageBuffer buffer, int oID);
00073   int train_removeObject(ImageBuffer buffer, unsigned int& siftImageID, int oID);
00074   // Specify object to add image to
00075   // Return model ID
00076   int train_addToObject(int objectID, std::string PGMFileName);
00077   int train_addToObject(int objectID, std::string PGMFileName, unsigned int& siftImageID, SiftMatch& matchFound);
00078   int train_addToObject(int objectID, ImageBuffer buffer);    
00079   int train_addToObject(int objectID, ImageBuffer buffer, unsigned int& siftImageID, SiftMatch& matchFound);
00080     
00081   int train_removefromObject(int objectID, std::string PGMFileName);
00082   int train_removefromObject(int objectID, std::string PGMFileName, unsigned int& siftImageID, SiftMatch& matchFound);
00083   int train_removefromObject(int objectID, ImageBuffer buffer);   
00084   int train_removefromObject(int objectID, ImageBuffer buffer, unsigned int& siftImageID, SiftMatch& matchFound);
00085   // Explicitly create new model for a given object
00086   // Returns model ID
00087   int train_addNewModel(int objectID, std::string PGMFileName);   
00088   int train_addNewModel(int objectID, std::string PGMFileName, unsigned int& siftImageID);
00089   int train_addNewModel(int objectID, ImageBuffer buffer);    
00090   int train_addNewModel(int objectID, ImageBuffer buffer, unsigned int& siftImageID);
00091     
00092   int train_removeModel(int objectID, std::string PGMFileName, int mID);    
00093   int train_removeModel(int objectID, std::string PGMFileName, unsigned int& siftImageID, int mID);
00094   int train_removeModel(int objectID, ImageBuffer buffer, int mID);   
00095   int train_removeModel(int objectID, ImageBuffer buffer, unsigned int& siftImageID, int mID);    
00096     
00097   /// Testing API calls
00098     
00099   // Detects all instances of a given known object in image
00100   void findObjectInImage(int objectID, std::string PGMFileName, std::vector<SiftMatch*>& matchesFound);
00101   void findObjectInImage(int objectID, ImageBuffer buffer, std::vector<SiftMatch*>& matchesFound);
00102     
00103   // Detects all instances of all known objects in image
00104   void findAllObjectsInImage(std::string PGMFileName, std::vector<SiftMatch*>& matchesFound);
00105   void findAllObjectsInImage(ImageBuffer buffer, std::vector<SiftMatch*>& matchesFound);
00106     
00107     
00108   /// Naming calls
00109     
00110   // Object name
00111   bool   setObjectName(int objectID, std::string Name);
00112   std::string getObjectName(int objectID);
00113   int    getObjectID  (std::string Name);
00114     
00115   // Model name
00116   bool   setModelName(int objectID, int modelID, std::string Name);
00117   std::string getModelName(int objectID, int modelID);
00118   int    getModelID  (int objectID, std::string Name);
00119     
00120     
00121   /// Parameter calls
00122     
00123   void   setParameter(const char* paramName, double paramVal);
00124   double getParameter(const char* paramName);
00125     
00126   /// List of parameters
00127   /*
00128     probOfMatch     - a possible transformation is rejected if the probability of matching (computed by Bayesian analysis) is below probofMatch
00129     errorThreshold  - a possible transformation is rejected if the error of match is above errorThreshold
00130   */
00131     
00132     
00133   /// File input and output
00134   void saveToFile(const std::string &filename, bool saveImages);
00135   void loadFile(const std::string &filename);
00136   static ImageBuffer sketchToBuffer(const DualCoding::Sketch<DualCoding::uchar>& sk);
00137 
00138   /**
00139      Advanced image database functions
00140      SiftTekkotsu maintains a database of all the training images and of the most recent testing image.
00141      The information stored for each image include:
00142      1. the image itself (stored as ImageBuffer)
00143      2. Gaussian space generated by SIFT++
00144      3. keypoints detected in the image by SIFT++, and used for matching by KnowledgeBase
00145      The below set of functions allow the user to access the information in the image database.
00146   **/
00147     
00148     
00149   /// Retrieve training image information
00150   // getImageBuffer assumes buffer.byteArray is not allocated, and will allocate memory that callee should free
00151   bool trainImage_getImageBuffer(  unsigned int siftImageID, ImageBuffer& buffer);
00152   bool trainImage_getGaussianSpace(unsigned int siftImageID, std::vector< std::vector< std::vector<int> > >& gaussianSpace);
00153   bool trainImage_getKeypoints(    unsigned int siftImageID, std::vector<keypoint*>& keypoints);
00154     
00155   /// Retrieve testing image information
00156   // getImageBuffer assumes buffer.byteArray is not allocated, and will allocate memory that callee should free
00157   void testImage_getImageBuffer(  ImageBuffer& buffer);
00158   void testImage_getGaussianSpace(std::vector< std::vector< std::vector<int> > >& gaussianSpace);
00159   void testImage_getKeypoints(    std::vector<keypoint*>& keypoints);
00160     
00161   //A test function that opens a file. To be deleted as soon as possible
00162   bool loadFile1(const char* filename);
00163 
00164 private:
00165   SiftTekkotsu(const SiftTekkotsu&);
00166   SiftTekkotsu& operator=(const SiftTekkotsu&);
00167 };
00168 
00169 #endif

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:51 2016 by Doxygen 1.6.3